Filter löschen
Filter löschen

I have a 2D matrix (81,000,000 x 2). Each row has a radius value and an intensity value. The radii are not in a monotonic in this 2D matrix. I want to sort 1st column from min to max and have column 2 move with it.

1 Ansicht (letzte 30 Tage)
I have a 9000 x 9000 matrix containing a radial distribution of energy from the center out. I want to plot Value vs. Radius. to fine R= 0 I look for the X,Y position of the maximum pixel,(X0,Y0). Then I go through the matrix and calculate the radius value for each pixel with R = sqrt((X-X0)^2 + (Y - Y0)^2). I store the Radius value and the intensity of that pixel in a two column matrix with Radius in Column 1, value in column 2. How do I sort radius values from min to max and have the associated column #2 go along with the sort? My (npts,2) matrix is about (81,000,000 x 2). I need to sort column 1 in ascending order but can't figure out how to make sure the value in column 2 move along with the sort so it is still associated with that radius value. Can you help?

Akzeptierte Antwort

Matt J
Matt J am 30 Okt. 2018
newmatrix=sortrows(oldmatrix,1);
  3 Kommentare
Matt J
Matt J am 31 Okt. 2018
You're welcome, but please Accept-click an answer that solved your issue.
dpb
dpb am 31 Okt. 2018
The name is the hint (vs just sort) and the description says "B = sortrows(A) sorts the rows of a matrix in ascending order based on the elements in the first column."

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 30 Okt. 2018
doc sortrows
Or, of course, you can do it yourself via
[~,ix]=sort(A(:,1)); % return index to sorted position of first column
A=A(ix,:); % reorder A by row in sorted order given by ix

Kategorien

Mehr zu Matrices and Arrays 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