variable to output name

2 views (last 30 days)
Leyon
Leyon on 1 Nov 2013
Edited: Matt J on 1 Nov 2013
name = 'adams'
c = 2x+4
I would like the value of "name" to be the variable for c. Therefore, instead of:
c = 2x+4
it would be:
adams = 2x+4
  5 Comments
Leyon
Leyon on 1 Nov 2013
So the only option seems to be to create struct variables?
Thanks. i already knew this but was hoping there was another alternative so I could have a clean fieldname
Matt J
Matt J on 1 Nov 2013
Edited: Matt J on 1 Nov 2013
It isn't the only option, but I recommended it to you here
as the safest one. There are dangers in using assignin, eval, load, etc... to create variables inexplicitly. See, for example,

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Nov 2013
a=[2 4 5];
assignin('base','adams',a)
  1 Comment
Azzi Abdelmalek
Azzi Abdelmalek on 1 Nov 2013
But I don't see why it's important to change the name of your variable?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!