使用单元格的内容作为符号变量的标签

时间:2017-05-02 14:38:00

标签: matlab command symbolic-math

我可以在Matlab命令中执行以下想法吗? 假设

a = 'c1Tl';

class(a)将返回单元格。

如何将a的内容用作我可以做的单元格变量

c1Tl = 3;

我尝试使用

sym(a) = 3;

将变量分配给'a'的内容,但这不是我的目的。 请帮忙解决我的问题! 谢谢!

1 个答案:

答案 0 :(得分:0)

最好的方法是使用struct数据类型。你会做这样的事情:

a = {'c1Tl'};
%Lets make a struct called data which will store the values
data.(a{1}) = 3; % The a{1} accesses the string stored in a and uses it to make a field in the structure data
%To access your data, now you can use
data.c1Tl