extract values from structure in matlab [closed]
Date: 2022-12-12 14:28:37
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.
Answer:
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.