How to read the symbols used in a variable name

2 次查看(过去 30 天)
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?

回答(1 个)

Walter Roberson
Walter Roberson 2012-11-3
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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by