[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: |
Wed, 14 Nov 2012 10:29:20 -0800 (PST) |
----- Original Message -----
> From: Yury T. <address@hidden>
> To: address@hidden
> Cc:
> Sent: Wednesday, November 14, 2012 6:32 PM
> Subject: Re: equivalent for C-style init: structname varname[] = {...} ?
>
> Jordi Gutiérrez Hermoso-2 wrote
>>> Arrgh! :) Sorry, I'd better go with Sergei's solution or with
> R, indeed.
>>> Thank you all the same.
>>
>> Sergei's if anything, is gonna be even *more* complicated, because
>> you'll have to replace {s.data} with a bigger expression so you can
>> select the ones you want.
>
> Actually, not so. Here's adaptation of my recent example with access to an
> individual fields of an item selected by arbitrary key. Reads almost
> naturally, right?
> Of course, I wasn't shown how make a full range iteration for such a data
> structure, so will have to work that out by myself :).
>
> s = consistent_struct\.
> (.
> "Buffat+Borel 1976 (5)", {"Buffat+Borel 1976 (5)", 13,
> 1337},
> "Coombes 1972 (2)", {"Coombes 1972 (2)", 13, 1337},
> "Lai+Guo+Petrova+ 1996 (2a)", {"Lai+Guo+Petrova+ 1996
> (2a)", 30, 505}
> );.
> .
> getfield( s, "Coombes 1972 (2)" ){1}.
> getfield( s, "Coombes 1972 (2)" ){2}.
> getfield( s, "Coombes 1972 (2)" ){3}.
>
>
>
>
> --
> View this message in context:
> http://octave.1599824.n4.nabble.com/equivalent-for-C-style-init-structname-varname-tp4646460p4646670.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
>
Pay attention to 'help fieldnames' in the session below:
"
octave:3> help fieldnames
`fieldnames' is a built-in function
-- Built-in Function: fieldnames (STRUCT)
Return a cell array of strings naming the elements of the structure
STRUCT. It is an error to call `fieldnames' with an argument that
is not a structure.
Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc <topic>' to search the manual index.
Help and information about Octave is also available on the WWW
at http://www.octave.org and via the address@hidden
mailing list.
octave:4> s.f1 = 1
s =
scalar structure containing the fields:
f1 = 1
octave:5> s.f2 = 2
s =
scalar structure containing the fields:
f1 = 1
f2 = 2
octave:6> fields = fieldnames(s)
fields =
{
[1,1] = f1
[2,1] = f2
}
octave:7> for fn = 1:numel(fields) printf("f=%s\n", fields{fn}); endfor
f=f1
f=f2
".
'fieldnames' is like 'keys' built-in Perl function.
Regards,
Sergei.
octave:8>
- Re: equivalent for C-style init: structname varname[] = {...} ?, (continued)
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury Tarasievich, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?,
Sergei Steshenko <=
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Yury T., 2012/11/14
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/15
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/16
- Re: equivalent for C-style init: structname varname[] = {...} ?, Ben Abbott, 2012/11/17
- Re: equivalent for C-style init: structname varname[] = {...} ?, Sergei Steshenko, 2012/11/17
- Re: equivalent for C-style init: structname varname[] = {...} ?, Dimitri Maziuk, 2012/11/18
- Re: equivalent for C-style init: structname varname[] = {...} ?, Jordi Gutiérrez Hermoso, 2012/11/18