精简圆柱图

时间:2017-02-12 05:12:37

标签: matlab

我已经在一个半径为1的圆柱体周围制作了这条流线图。有没有办法去除圆柱内部的什么东西,甚至可能是不同颜色的圆柱体?

enter image description here

 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');

2 个答案:

答案 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

red circle

您也可以尝试直接更改XY(而不是Ypsi):

psi(Y>-1 & X>-1 & Y<1 & X<1) = nan;

但结果有点不同。

red circle 2

答案 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;)

https://www.mathworks.com/help/matlab/ref/rectangle.html