필터 지우기
필터 지우기

How to name a Variable as a string?

조회 수: 1 (최근 30일)
Simon
Simon 2013년 5월 29일
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에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by