Matlab代码不会绘制部分函数

the*_*guy 5 matlab vector matlab-figure

我最近尝试在流体问题集中为一个教程问题绘制一些velocicty字段.我写了以下Matlab代码

clear;

h_theta_multiple=0.01;
h_theta=h_theta_multiple*2*pi;
h_rho=0.1;

[theta,rho] = meshgrid(0:h_theta:2*pi,0:h_rho:5);
[x1,x2] = pol2cart(theta,rho);

N=[1 2 3 -1 -2 -3];

figure
for i=1:length(N)
n=N(i);
u1 = rho.^n .* cos(n.*theta); 
u2 = rho.^n .* sin(n.*theta); 
subplot(2,3,i);
quiver(x1,x2,u1,u2);
end

figure
for i=1:length(N)
n=N(i);
u1 = -rho.^n .* sin(n.*theta); 
u2 = rho.^n .* cos(n.*theta); 
subplot(2,3,i);
quiver(x1,x2,u1,u2);
end
Run Code Online (Sandbox Code Playgroud)

它给了我以下内容 第一功能

在此输入图像描述

分别用于第一和第二功能.我无法弄清楚为什么它没有绘制n为负的...我试图隔离所有但最终无法调试它.

Lui*_*ndo 6

问题是对于负n矩阵u1并且u2在某些条目中包含无限值.quiver自动缩放值,因此所有内容都被压缩到零,因此不会显示在图表中.

解决方案是通过以下方式替换无限值NaN:

clear;

h_theta_multiple=0.01;
h_theta=h_theta_multiple*2*pi;
h_rho=0.1;

[theta,rho] = meshgrid(0:h_theta:2*pi,0:h_rho:5);
[x1,x2] = pol2cart(theta,rho);

N=[1 2 3 -1 -2 -3];

figure
for i=1:length(N)
n=N(i);
u1 = rho.^n .* cos(n.*theta); 
u2 = rho.^n .* sin(n.*theta); 
u1(isinf(u1)) = NaN; % replace infinite values by NaN
u2(isinf(u2)) = NaN;
subplot(2,3,i);
quiver(x1,x2,u1,u2);
end

figure
for i=1:length(N)
n=N(i);
u1 = -rho.^n .* sin(n.*theta); 
u2 = rho.^n .* cos(n.*theta); 
u1(isinf(u1)) = NaN; % replace infinite values by NaN
u2(isinf(u2)) = NaN;
subplot(2,3,i);
quiver(x1,x2,u1,u2);
end
Run Code Online (Sandbox Code Playgroud)

这给了

在此输入图像描述

在此输入图像描述