How to plot a matrix in polar coordinates with color?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Andrew Newell
le 25 Avr 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!