2017-02-12 63 views
2

我制作了半径为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

可以屏蔽你不想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; 

bu结果有点不同。

red circle 2

+0

如果设置了圆的(矩形的)“FaceColor”属性你不会需要屏蔽。 –