# using surf and pol2cart on matrix

22 views (last 30 days)
prrrrr on 25 Jun 2020
Commented: Star Strider on 26 Jun 2020
hello i have a 512x1000 matzrix
the coordinates are there divided into lines (x) as radius and columns (y) as angles. To each point in the matrix belongs a value (z).
How do I get the polar coordinates into cartesian coordinates (pol2cart). And can it plot at the end (with surf?)?
I would like to get in principle from my picture A the picture B
EDIT Forgot Code Example:
angles = (0:pi/8:2*pi)';
Adam Danz on 25 Jun 2020
Are the angles vector and the radii vector supposed to be different lengths?
How do those values plot a circle?

Star Strider on 25 Jun 2020
Edited: Star Strider on 25 Jun 2020
The matrix you have is actually the ‘Z’ matrix. You need to create separate radius and angle matrices of the same size (use ndgrid or meshgrid for that, and be aware that their outputs are not the same), then use all three of those matrices as arguments to pol2cart. You will likely need to experiment a bit.
EDIT — (25 Jun 2020 at 23:17)
Using code example, try something like this:
Z = rand(512,1000); % Create 'Z'
angles = linspace(0, 2*pi, size(Z,2));
[X, Y, Z] = pol2cart(A, R, Z);
figure
surf(X, Y, Z)
grid on
.
##### 2 CommentsShowHide 1 older comment
Star Strider on 26 Jun 2020
As always, my pleasure!

R2020a

### Community Treasure Hunt

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

Start Hunting!