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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!