extract values from structure in matlab [closed]

2019-09-21 11:47发布

问题:

I have a question please if we have structure with 3 dimension and each field of them has 7 values how can extract each value from each field of this structure separately.

回答1:

Just use indexing:

>> s(1,1,1).data = [1 2 3 4];
>> s(1,1,2).data = [10 20 30 40 50]; %// example struct
>> s(1,1,2).data(3)
ans =
    30
>> s(1,1,2).data(2:4)
ans =
    20    30    40

Also, it's better not to use struct as a variable name, because struct is a built-in function.



标签: matlab struct