Suppose we have structure arrays
a.b =[1 2; 3 4]
and
c(1).b =[1 2], c(2).b =[3 4].
Now, let's try ( ) on both of them.
>> a.b= [1 2; 3 4]
a =
b: [2x2 double]
>> c(1).b =[1 2]
c =
b: [1 2]
>> c(2).b =[3 4]
c =
1x2 struct array with fields:
b
>> (a.b)
ans =
1 2
3 4
>> (c.b)
ans =
1 2
ans =
3 4
and [ ]
>> [a.b]
ans =
1 2
3 4
>> [c.b]
ans =
1 2 3 4
Through the example, it is easy to see the difference. If we also have d ='more', what will happen if we type c(1).(d) =1?
>> c(1).(d) =1Thus ( ) can be used to create dynamic field names. So far, { } haven't been mentioned because this pair of curly braces are mostly for cells.
c =
1x2 struct array with fields:
b
more
hello... hapi blogging... have a nice day! just visiting here....
ReplyDeleteI have a question, i am relatively new at programming, so could someone please tell me why to use an empty matrix when using a for loop?
ReplyDeletethanks! I was trying to remember the bracket syntax for extracting an array of field values from a struct array.
ReplyDelete