Search code examples
matlabcommandsymbolic-math

Use the content of a cell as a label of a symbolic variable


Can I do the following idea in Matlab command? Assuming that

a = 'c1Tl';

class(a) will return cell.

How I can use the content of an as a cell variable which I can do

c1Tl = 3;

I try to use

sym(a) = 3;

to assign a variable to the content of 'a' but It is not my purpose. Please help to solve my problem! Thank you!


Solution

  • The best way to do that is to use a struct data type. You would do something like this:

    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