Borrar filtros
Borrar filtros

to sort a matrix

1 visualización (últimos 30 días)
Rengin
Rengin el 25 de En. de 2016
Editada: Stephen23 el 25 de En. de 2016
% Dear user!
% I have A and B matrices as below
A=[1;2;3;4;5];
B=[12;14;18;16;10];
C=[A B];
% I want to create a D matrix sorting the second column of C matrix as
% below:
D=[5 10;1 12;2 14;4 16;3 18];
% How can I do it? Thank for your help?

Respuesta aceptada

Stephen23
Stephen23 el 25 de En. de 2016
Editada: Stephen23 el 25 de En. de 2016
Use sortrows with its optional second argument to select the second column:
>> A = [ 1; 2; 3; 4; 5];
>> B = [12;14;18;16;10];
>> sortrows([A,B],2)
ans =
5 10
1 12
2 14
4 16
3 18

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by