Combining Matrices Concerning Stats

1 次查看(过去 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.

采纳的回答

Image Analyst
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 CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by