具有单元格数组的Matlab动态字段名称结构 [英] Matlab dynamic fieldnames structure with cell arrays
本文介绍了具有单元格数组的Matlab动态字段名称结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用动态字段名访问以下结构路径:
How can i access the following structure path with dynamic fieldnames:
var = 'refxtree.CaseDefinition.FlowSheetObjects.MaterialStreamObjects{8}.MaterialStreamObjectParams.Pressure.Value.Text';
fields = textscan(var,'%s','Delimiter','.');
refxtree.(fields{:})
不起作用,因为MaterialStreamObjects包含一个单元格数组,我要访问该单元格的第8个单元格,然后继续沿结构路径向下移动.
refxtree.(fields{:})
does not work because MaterialStreamObjects contains a cell array of which I want to access the 8th cell and then continue down the structure path.
最后,我要获取并设置字段值.
In the end I want to get and set the fieldvalues.
推荐答案
在这种情况下,仅使用EVAL会更容易:
In this case, it is easier to just use EVAL:
str = 'refxtree.CaseDefinition.FlowSheetObjects.MaterialStreamObjects{8}.MaterialStreamObjectParams.Pressure.Value.Text';
%# get
x = eval(str)
%# set
evalc([str ' = 99']);
这篇关于具有单元格数组的Matlab动态字段名称结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文