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!
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!