Borrar filtros
Borrar filtros

Combining Matrices Concerning Stats

3 visualizaciones (últimos 30 días)
TS
TS el 28 de Feb. de 2015
Editada: Star Strider el 28 de Feb. de 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.

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Feb. de 2015
Editada: Image Analyst el 28 de Feb. de 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 :-)

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by