help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: equivalent for C-style init: structname varname[] = {...} ?


From: Sergei Steshenko
Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
Date: Mon, 12 Nov 2012 12:36:37 -0800 (PST)





----- Original Message -----
> From: Yury T. <address@hidden>
> To: address@hidden
> Cc: 
> Sent: Monday, November 12, 2012 7:39 PM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
> 
>T hank you guys, but all this seems to be not I'm looking for.
> 
> Indeed, I'm looking for the arrays of structs and also I want to initialise
> those with undetermined number of structs-constants. Like I showed in my
> example, anyway.
> 
> Why do I need this? I have an undetermined number of datafiles which I need
> to process (fit with least-squares) using certain parameters specific to
> each file. And I'd like to have some annotations to those files, too (paper
> from which the data is derived etc.). The processing itself is quite
> uncomplicated, so I was figuring on use of something like following
> (C-style) right in my .m script:
> 
> name[] = {
> 
> { "file1.dat", par1_1, par2_1, "ID1" }, # comment
> { "file2.dat", par1_2, par2_2, "ID2" }, # comment
> 
> };
> 
> which I would then expand (or contract) as necessary and just rerun the .m
> script. Previously I was doing just that sort of thing in R.
> 
> Of course, I might just have to go with a printf-format-style reading of the
> text file, but that will at the very least force me to use a separate file.
> 
> @Jordi: indeed, I feel that the documentation is somewhat unclear and not
> very happily structured w/r to the arrays of all kind. Don't get me wrong,
> you guys are doing sterling work, but...
> 
> 
> 
> 
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/equivalent-for-C-style-init-structname-varname-tp4646460p4646475.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

Then isn't this:

"
octave:1> par1_1=1
par1_1 =  1
octave:2> par2_1=2
par2_1 =  2
octave:3> par1_2=3
par1_2 =  3
octave:4> par2_2=4
par2_2 =  4
octave:5> name = {{ "file1.dat", par1_1, par2_1, "ID1" }, { "file2.dat", 
par1_2, par2_2, "ID2" }}
name =
{
  [1,1] =
  {
    [1,1] = file1.dat
    [1,2] =  1
    [1,3] =  2
    [1,4] = ID1
  }
  [1,2] =
  {
    [1,1] = file2.dat
    [1,2] =  3
    [1,3] =  4
    [1,4] = ID2
  }
}
octave:6>                
"

as straightforward as it can be ?

--Sergei.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]