Effacer les filtres
Effacer les filtres

How to name a Variable as a string?

1 vue (au cours des 30 derniers jours)
Simon
Simon le 29 Mai 2013
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!

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by