How to plot a matrix in polar coordinates with color?

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

采纳的回答

Andrew Newell
Andrew Newell 2017-4-25
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by