How to name a Variable as a string?

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

采纳的回答

Walter Roberson
Walter Roberson 2013-5-29
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by