Azzera filtri
Azzera filtri

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 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 30 Ott 2018
newmatrix=sortrows(oldmatrix,1);
  3 Commenti
dpb
dpb il 31 Ott 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."

Accedi per commentare.

Più risposte (1)

dpb
dpb il 30 Ott 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

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by