-1

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!

Karim
  • 252
  • 1
  • 4
  • 17
  • 1
    You really don't want those variables, as dynamic variable naming is [bad, very bad](http://stackoverflow.com/questions/32467029/how-to-put-these-images-together/32467170#32467170). – Adriaan May 02 '17 at 18:20
  • My purpose is made a script that can store the object after loading because I have many objects to load, the object is used in later. If I do not do so, I have to manually generate many variable names. – Karim May 02 '17 at 23:18
  • No you don't see the duplicate. Just use a structure data type. The answer you accepted (and thus hopefully use) doesn't use dynamically named variables either. Just stick with the structures. – Adriaan May 03 '17 at 05:47
  • Thank you for your suggestion! – Karim May 04 '17 at 00:24

1 Answers1

0

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
Adriaan
  • 17,741
  • 7
  • 42
  • 75
ammportal
  • 991
  • 1
  • 11
  • 27
  • My purpose is made a script that can store the object after loading because I have many objects to load, the object is used in later. If I do not do so, I have to manually generate many variable names. – Karim May 02 '17 at 23:18