How to plot a matrix in polar coordinates with color?

1 view (last 30 days)
Hi I've been trying to plot this function in Matlab which is in polar coordinates:
V(rho, phi) = A * Sum(1/m * (rho/B)^m * sin(m*phi)) %m:1:1000:odd
A & B are constants and summation is on odd numbers from 1 to say 1000.
I wrote the following code to store a V for each rho and phi in a matrix. So the first column of this matrix is rho, the second one is phi and the third one is V. How can I plot rho and phi and represent V as the color so I'll have a 2D polar plot with color?
clc
clear all
v0=10; A=4.*v0./pi;k=1;
b=5;
n=1:2:20;
for r=0.5:0.5:b
for ph=0:0.2:2*pi
V1=sum( A.*(1./n).*((r/b).^n).*sin(n*ph));
M(k,1:3)=[r,ph,V1];
k=k+1;
end
end

Accepted Answer

Andrew Newell
Andrew Newell on 25 Apr 2017
I think most approaches will involve converting the coordinates to Cartesian. Here is one approach:
v0=10; A=4.*v0./pi;k=1;
b=5;
n=1:2:20;
r = 0.5:0.5:b;
ph = 0:0.2:2*pi;
[r,ph] = meshgrid(r,ph);
V1 = zeros([size(r) numel(n)]);
for ii=1:numel(n)
V1(:,:,ii) = A*(1/n(ii))*((r/b).^n(ii)).*sin(n(ii)*ph);
end
V1 = sum(V1,3);
contourf(r.*cos(ph),r.*sin(ph),V1)
axis square
colorbar
  2 Comments
A Hash
A Hash on 25 Apr 2017
Thank you. This is exactly what I was looking for.
A Hash
A Hash on 25 Apr 2017
Quick question. How can I plot the gradient of V the same way?

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!