在Matlab中从结构中提取值 [英] extract values from structure in matlab

查看:156
本文介绍了在Matlab中从结构中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,如果我们有一个3维的结构,并且每个字段有7个值,那么如何分别从该结构的每个字段中提取每个值.

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.

推荐答案

只需使用索引:

>> 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

此外,最好不要使用struct作为变量名,因为struct是内置函数.

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

这篇关于在Matlab中从结构中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆