MATLAB Answers


Sorting matrix

Asked by FIR
on 18 Feb 2012
Latest activity Edited by Cedric Wannaz
on 15 Oct 2013
    I have amatrix
    A=[1 2 13;
  10 1 2; 
  8 14 3]
    I want to sort 2nd column,so the corresponding values must also change
    A=[10 1 2;
  1 2 13;
  8 14 3] 




No products are associated with this question.

1 Answer

Answer by Wayne King
on 18 Feb 2012
 Accepted answer

[~,indices] = sort(A(:,2));
A = A(indices,:);

  1 Comment

on 18 Feb 2012

Thanks Wayne can u answer the question in plz

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!