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 次查看(过去 30 天)
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?

采纳的回答

Matt J
Matt J 2018-10-30
newmatrix=sortrows(oldmatrix,1);
  3 个评论
dpb
dpb 2018-10-31
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."

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2018-10-30
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

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by