sorting a matrix then applying the sort to another matrix

Hello, i am working in spherical coordinates and want to sort my data to look along a cross section of my data to plot radius vs. theta for a fixed azimuth.
I have three 2D matrices (mxn) A = elevation, B = azimuth, C = radius. There are repeated cases of [A,B] with a unique C. The data in A and B is rounded to "bin" the results. I have then converted to cartesian coordinates to view [x,y,z]
How do I create and sort the new X,Y,Z matrix such that it is ordered like the plot, i.e. X(1,1), Y(1,1) ,Z(1,1) is the top corner pixel in my image.

4 Comments

"How do I create and sort the new X,Y,Z matrix such that it is ordered like the plot"
What is the "order" of the plot?
maybe a different way to think about it... How do I use this data to create a new 3 column matrix where column 1 is elevation column 2 is azimuth, and each row is a unique elevation, azimuth combination. Then the third column is the sum of all radius values at that specific elevation and azimuth
new sorted vector:
elevation azimuth radius
0 0 sum of all points at 0 elevation and 0 azimuth
0 10 sum of all points at 0 elevation and 10 azimuth
... ... ...
0 360 sum of all points at 0 elevation and 360 azimuth
1 0 ....
1 10 ....
... ... ....
1 360 ...
... ... ...
90 0 ...
90 10 ...
... ... ...
90 360 sum of all points at 90 elevation and 360 azimuth
sortrows is not going to help with calculating the sum of the radii for a given elevation, azimuth combination.

Sign in to comment.

Answers (1)

"How do I use this data to create a new 3 column matrix where column 1 is elevation column 2 is azimuth, and each row is a unique elevation, azimuth combination. Then the third column is the sum of all radius values at that specific elevation and azimuth"
Like Stephen, I do not understand your original question but the bit above is easy;
%inputs:
%elevation: Your A matrix with a more useful name. Can be any shape and size
%azimuth: Your B matrix with a more useful name. Same size as elevation
%radius: Your C matrix. Same size as the others
[urows, ~, subs] = unique([elevation(:), azimuth(:)], 'rows');
result = [urows, accumarray(subs, radius(:))]; %default function for accumarray is sum which is exactly what you want
All done!
Note that for clarity I would store the result in a table:
result = array2table(result, 'VariableNames', {'elevation', 'azimuth', 'sumradii'})

Categories

Asked:

on 24 Jan 2019

Commented:

on 25 Jan 2019

Community Treasure Hunt

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

Start Hunting!