필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

what's a smarter way to associate numbers in an array to variable names?

조회 수: 1 (최근 30일)
Fede C 2018 London
Fede C 2018 London 2018년 11월 28일
마감: Guillaume 2018년 11월 28일
I've asked this in the comments as a follow up to another question, but I think I broke etiquette because it wasn't related.. I'm reposting it here as a standalone question so hopefully others with similar queries can look at how something like this can be solved.
I’ve done a pretty ugly section of code that requires quite a bit of manual work, which is innocuous with 4 columns of random data, but would be a pain once I roll out the program to real data, of which I have tons. But ugly was all I was able to conjure up.
So, this:
[nRows, nCols] = size( data ) ;
combinations =nchoosek(1:nCols,2);
gives me an array of unique combinations:
1 2
1 3
1 4
2 3
2 4
3 4
In order to associate each number in array combinations to the variable names, where these are contained in array ‘headers’, from:
headers = raw(1,1:4);
I’ve done this:
Nrowscombinations=size(combinations,1);
Ncolumnscombinations=size(combinations,2);
nameVar = strings(Nrowscombinations,Ncolumnscombinations);
for iii=1 : Nrowscombinations
for jjj =1 : Ncolumnscombinations
if combinations(iii,jjj)==1
nameVar(iii,jjj)=headers{1,1};
end
if combinations(iii,jjj)==2
nameVar(iii,jjj)=headers{1,2};
end
if combinations(iii,jjj)==3
nameVar(iii,jjj) = headers{1,3};
end
if combinations(iii,jjj)==4
nameVar(iii,jjj)=headers{1,4};
end
end
end
And nameVar is what I want, a 6x2 array of strings containing:
X Y
X V
X Z
Y V
Y Z
V Z
Which is what I want.
Is there an intelligent way of doing this, one that wouldn’t have me manually insert that co-ordinates and the numbers like that –you can imagine how hideous this becomes with hundreds of variables?

답변 (0개)

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by