extract values from structure in matlab [closed]

2019-09-21 11:33发布

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.

标签: matlab struct
1条回答
不美不萌又怎样
2楼-- · 2019-09-21 12:15

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.

查看更多
登录 后发表回答