MATLAB: How to name a Variable as a string

variable

Hi, my problem is that i got a bunch of named variable already but I am using
V = nchoosek({VAR1,VAR2,VAR3,VAR4,VAR5,VAR6},4)
B = nchoosek(6,4)
for i =1:B
A{i} = V(i,:)
end
Now in A, i got all the combinations of nchoosek i asked but the var are all mixed up, i would like to have a way to name them so that I can track the varnames in each combination. Thank you!

Best Answer

Are there any elements in common between the VAR* ? If there are, then saying "which" variable the common element came from is not meaningful.
If there are not, then create a lookup table such as
{ repmat('VAR1', 1, length(VAR1));
repmat('VAR2', 1, length(VAR2)) }
and then in the nchoosek call, for VAR1 substitute 1:length(VAR1), for VAR2 substitute length(VAR1)+1 : length(VAR1)+length(VAR2) and so on, so that you are sending in integers 1 : length(everything together). Then for each nchoosek result, you can index the lookup table at each element in order to find out which variable name the element originated from.