Filter löschen
Filter löschen

Combining Matrices Concerning Stats

3 Ansichten (letzte 30 Tage)
TS
TS am 28 Feb. 2015
Bearbeitet: Star Strider am 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 28 Feb. 2015
Bearbeitet: Image Analyst am 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 :-)

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by