How to plot a matrix in polar coordinates with color?

1 回表示 (過去 30 日間)
A Hash
A Hash 2017 年 4 月 25 日
コメント済み: A Hash 2017 年 4 月 25 日
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
  2 件のコメント
A Hash
A Hash 2017 年 4 月 25 日
Thank you. This is exactly what I was looking for.
A Hash
A Hash 2017 年 4 月 25 日
Quick question. How can I plot the gradient of V the same way?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by