From: bob on
Hi All,
I have a structure (substruct2) within a structure (mainstruct) and I
want to list the contents of a field across all elements of the main
structure without using a loop. For example,

>> mainstruct(1)

ans=

substruct1
substruct2
substruct3

>> mainstruct(1).substruct2

ans=

field1
field2
field3

>> mainstruct(1).substruct2.field3

ans=

7

I want to create an array of values from field3 of substruct2 for
each of the elements in mainstruct. I can do this by making a loop:

for i=1:10
myarray(i)= mainstruct(i).substruct2.field3;
end

Is there any way to do this without using a loop?

thanks,

b
From: per isakson on
bob wrote:
>
>
> Hi All,
> I have a structure (substruct2) within a structure (mainstruct) and
> I
> want to list the contents of a field across all elements of the
> main
> structure without using a loop. For example,
>
>>> mainstruct(1)
>
> ans=
>
> substruct1
> substruct2
> substruct3
>
>>> mainstruct(1).substruct2
>
> ans=
>
> field1
> field2
> field3
>
>>> mainstruct(1).substruct2.field3
>
> ans=
>
> 7
>
> I want to create an array of values from field3 of substruct2 for
> each of the elements in mainstruct. I can do this by making a
> loop:
>
> for i=1:10
> myarray(i)= mainstruct(i).substruct2.field3;
> end
>
> Is there any way to do this without using a loop?
>
> thanks,
>
> b

Don't think so:

m.s.f=1;
m(2).s.f=2;
m(3).s.f=3;

>> [ m(:).s.f ]
??? Scalar index required for this type of multi-level indexing.

>> [ m.s.f ]
??? Dot name reference on non-scalar structure.

/ per
 | 
Pages: 1
Prev: Using xlswrite
Next: TAylor Series