Combining Matrices Concerning Stats

1 view (last 30 days)
TS
TS on 28 Feb 2015
Edited: Star Strider on 28 Feb 2015
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.

Accepted Answer

Image Analyst
Image Analyst on 28 Feb 2015
Edited: Image Analyst on 28 Feb 2015
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 :-)

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!