How to draw an polar image under polar coordinate

Hello, I have a problem when drawing a polar image. The problem is like this. I have a matrix A in which a distribution under polar coordinate Z=f(theta,r) is described by its elements Z=f(theta,r)=A(i,j). I want to draw it under polar coordinate like the function image.m for cartesian coordinates.

Answers (1)

N = 150;
maxr = 20;
theta = linspace(0, 2*pi, N+1);
r = linspace(0, maxr, N+1);
theta = theta(1:end-1); %throw away 2*pi since it duplicates 0
r = r(2:end); %throw away 0 since that's at the center
[THETA, R] = ndgrid(theta, r);
Z = f(THETA,R);
[X, Y] = pol2cart(THETA,R);
surf(X, Y, Z);
anything beyond that is drawing the circles and labeling

4 Comments

Thanks a lot dude, but may I ask that is there a way not to transfer polar into cartesian to draw it like the function polar.m does in matlab?
polar.m translates its data to cartesian to do its drawing.
The setup in this code establishes a non-uniform coordinate grid, which surf() is perfectly happy with. surf is not going to place the elements on a rectangular grid: it will put the elements into a circle.
There is no true polar coordinate system in MATLAB. polar.m uses entirely cartesian internally, drawing circles in cartesian coordinates, labeling in cartesian coordinates, transforming the input polar coordinates to cartesian coordinates to draw the lines.
Note: in the days since I posted the above, Mathworks did add polaraxes that is not in cartesian coordinates at any user-visible level, and added polarplot
But there is still no Mathworks-provided polar image function. There are File Exchange contributions for polar images, and there is the surf work-around that I posted above.

Sign in to comment.

Categories

Asked:

on 17 Jan 2016

Commented:

on 18 Apr 2023

Community Treasure Hunt

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

Start Hunting!