A basic question for which I need some clarifications:
I have a problem statement - "Create a variable s is a 3-by-4 structure with fields a, b, and c. Each of these fields is a 2-by-5 array of class double"
So first I create a 2-by-5 array of class double :
>> d = [1.0 2.0 3.0 4.0 5.0; 1.0 2.0 3.0 4.0 5.0]
The 4 structures :
s1 = struct('a', d,'b',d,'c', d)
s2 = struct('a', d,'b',d,'c', d)
s3 = struct('a', d,'b',d,'c', d)
s4 = struct('a', d,'b',d,'c', d)
Then the final structure:
>> S = [s1 s2 s3 s4;s1 s2 s3 s4;s1 s2 s3 s4]
S =
3x4 struct array with fields:
a
b
c
Does the above example meets the problem statement - is there any difference in-between "3-by-4 structure" and "3x4 struct array" as per example I mentioned - if yes then how do I create a 3-by-4 structure ?
Also if the above example is correct then I am confused of output of below commands:
S, S(:), S(2:3,1:3), S(2,3).a and S(2:3,3:4).a
>> S
S =
3x4 struct array with fields:
a
b
c
>> S(:)
ans =
12x1 struct array with fields:
a
b
c
What are the values returned and how can I see them? Note
>> S(:)(1)
??? Error: () Indexing must appear last in an index expression.
If S(:) returns a 12x1 struct array with fields
>> S(2:3,1:3)
ans =
2x3 struct array with fields:
a
b
c
Why I am not able to get to see all elements of structure 'S'
>> S(2,3).a
ans =
1 2 3 4 5
1 2 3 4 5
>> S(2:3,3:4).a
ans =
1 2 3 4 5
1 2 3 4 5
ans =
1 2 3 4 5
1 2 3 4 5
ans =
1 2 3 4 5
1 2 3 4 5
ans =
1 2 3 4 5
1 2 3 4 5
>>