i'm reading some data from xml file (can be any length).
i can read the length of it.
each item/row in xml file is transfered to a struct data type in matlab.
i wanna initialize some variables to the the length of the data and put the data to a specific variable according the struct information.
how to initialize array of structs - sets all the values to zero?
|
|
0
|
|
|
|
Reply
|
michael
|
4/27/2010 6:08:05 PM |
|
"michael" <bezenchu@gmail.com> wrote in message <hr7965$hsa$1@fred.mathworks.com>...
> i'm reading some data from xml file (can be any length).
> i can read the length of it.
> each item/row in xml file is transfered to a struct data type in matlab.
>
> i wanna initialize some variables to the the length of the data and put the data to a specific variable according the struct information.
>
> how to initialize array of structs - sets all the values to zero?
one of the solutions
s.a=zeros(1,4);
s.b=nan(1,5);
s(1:5)=s;
s.a
%{
ans = % <- s(1).a
0 0 0 0
ans =
0 0 0 0
ans =
0 0 0 0
ans =
0 0 0 0
ans =
0 0 0 0
%}
us
|
|
0
|
|
|
|
Reply
|
us
|
4/27/2010 6:15:22 PM
|
|
michael wrote:
> how to initialize array of structs - sets all the values to zero?
When you use struct() to declare the field names, if you use {} around the
values, then as many struct array members will be created as there are values
in the cell, with each member set to the cell value.
>> struct('foo', mat2cell(zeros(5,4),ones(5,1)))
ans =
5x1 struct array with fields:
foo
>> ans(3).foo
ans =
0 0 0 0
|
|
0
|
|
|
|
Reply
|
Walter
|
4/27/2010 6:25:22 PM
|
|