Combining Matrices Concerning Stats
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm having trouble getting matrices in separate strings to function with one another. The matrices that I have:
R=[1;2;3;4;5;6;7;8;9;10];
N=['Kent';'Virg';'Gonz';'Duke';'Wisc';'Vill';'Ariz';'Kans';'Utah';'Notr'];
W=[25;23;26;22;23;23;22;21;20;22];
L=[0;1;1;3;2;2;3;4;4;4];
need to be able to change with one another. This is because I am using sortrows right now to align teams in alphabetical order and I need the other matrices to follow. For example when the first element in matrix N is Ariz, I need R to be 7, W to be 22, and L to be 3 as these are statistics. Another problem I'm having is getting these same matrices to display next to each other. The set up I have now is fprintf('%2d %s %2d %2d\n',[R,sortrows(N,1),W,L]') which unfortunately does not work as sortrows(N,1) seems to skew the display. If anyone could help it would be greatly appreciated.
댓글 수: 0
채택된 답변
Image Analyst
2015년 2월 28일
편집: Image Analyst
2015년 2월 28일
Try this:
R=[1;2;3;4;5;6;7;8;9;10];
N=['Kent';'Virg';'Gonz';'Duke';'Wisc';'Vill';'Ariz';'Kans';'Utah';'Notr']
W=[25;23;26;22;23;23;22;21;20;22]
L=[0;1;1;3;2;2;3;4;4;4]
% Sort them.
[sortedArray, sortIndices] = sortrows(N, 1)
R = R(sortIndices)
W = W(sortIndices)
L = L(sortIndices)
Of course if you were to sort them in order of decreasing teams skill/ability, Arizona would be also be #1 again in that sorting :-)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!