我已经在一个半径为1的圆柱体周围制作了这条流线图。有没有办法去除圆柱内部的什么东西,甚至可能是不同颜色的圆柱体?
clear
% make axes
xymax = 2;
x = linspace(-xymax,xymax,100);
y = linspace(-xymax,xymax,100);
% note that x and y don't include 0
[X,Y] = meshgrid(x,y);
R = sqrt(X.^2 + Y.^2);
sin_th = Y./R;
cos_th = X./R;
U = 1;
a = 1;
psi = U*(R - a*a./R).*sin_th;
figure
contour(X,Y,psi,[-3:.25:3],'-b');
答案 0 :(得分:2)
您可以使用nan
屏蔽您不想要绘制的内容:
psi((Y>0 & psi<0) | (Y<0 & psi>0)) = nan;
而不是draw a circle:
rectangle('Position', [-1 -1 2 2],'Curvature',[1 1],'EdgeColor','r')
以下是代码和结果:
% make axes
xymax = 2;
x = linspace(-xymax,xymax,100);
y = linspace(-xymax,xymax,100);
% note that x and y don't include 0
% [X,Y] = meshgrid(x(x<-1 | x>1),y(y<-1 | y>1));
[X,Y] = meshgrid(x,y);
R = sqrt(X.^2 + Y.^2);
sin_th = Y./R;
cos_th = X./R;
U = 1;
a = 1;
psi = U*(R - a*a./R).*sin_th;
% mask the inner part with nans:
psi((Y>0 & psi<0) | (Y<0 & psi>0)) = nan;
contour(X,Y,psi,[-3:0.25:3],'-b');
% draw a circle:
rectangle('Position', [-1 -1 2 2],'Curvature',[1 1],'EdgeColor','r')
axis equal
您也可以尝试直接更改X
和Y
(而不是Y
和psi
):
psi(Y>-1 & X>-1 & Y<1 & X<1) = nan;
但结果有点不同。
答案 1 :(得分:1)
这是违反直觉的,但hold on
rectangle('Position',[-R,-R,2*R,2*R],'Curvature',[1,1],'FaceColor',[1 1 0])
功能可用于绘制圆圈!
{{1}}
也可以随意使用线条属性(&#39; EdgeColor&#39;&#39; LineWidth&#39;)