How to read the symbols used in a variable name

1 view (last 30 days)
Firstly, I am not certain this is even possible. What I am trying to do is read the individual characters of the name of the variable itself. IE, I have a variable named AB and a variable named AC. I want to define another variable as "A_first"(since A is the first variable in the list) that is equal to the value and AB and AC (in an array). Does anyone know if this is possible?

Answers (1)

Walter Roberson
Walter Roberson on 3 Nov 2012
varname = @(v) inputname(1);
AB = 321;
varname(AB) %would be 'AB'
However, what you are trying to do is seldom a good idea. See http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

Tags

Community Treasure Hunt

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

Start Hunting!