MATLAB: Interchange variable names and strings

stringsvariable names

How do I convert a string to a variable name (and vice versa)?
I want to read in a string, and use it as a variable name, such as when I load a *.mat, in which the variable names depend upon which program generated/saved the *.mat.
I can see it useful to convert a variable name to a string.

Best Answer

<http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Consider using
S = load('YourMATFile.mat');
the_var_names = fieldnames(S);
second_var = S.(the_var_names{2});
You can slice, dice, trice, even julienne!