Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: struct literal?
Replies: 2   Last Post: Sep 4, 2012 11:38 AM

 Messages: [ Previous | Next ]
 Andreas Lobinger Posts: 12 Registered: 7/29/11
Re: struct literal?
Posted: Sep 4, 2012 11:38 AM

Aloha,

"Steven_Lord" <slord@mathworks.com> wrote in message <k255l9\$7bn\$1@newscl01ah.mathworks.com>...
> "Andreas Lobinger" <andreas.lobinger@nsn.com> wrote in message
> news:k2555d\$5a5\$1@newscl01ah.mathworks.com...

> > this is tricky. Maybe i'm missing some basics?
>
> See the second item in the Tips section of the documentation for STRUCT:
> http://www.mathworks.com/help/techdoc/ref/struct.html
> d = struct('freq',[1 1],'RAT',[1 2],'name',{{'a-string','b-string'}})

Many thanks for the quick and correct answer.

btw: this not only shows up in doc, but already in help struct...

To create fields that contain cell arrays, place the cell arrays
within a VALUE cell array. For instance,
s = struct('strings',{{'hello','yes'}},'lengths',[5 3])
creates the 1-by-1 structure
s =
strings: {'hello' 'yes'}
lengths: [5 3]

So this can be considered RTFM on my side. (but: help struct ends with this example, so reordering might be better here...)

Example
s = struct('type',{'big','little'},'color','red','x',{3 4})

Wishing a happy day,
Andreas

Date Subject Author
9/4/12 Andreas Lobinger
9/4/12 Steven Lord
9/4/12 Andreas Lobinger