How to plot matlab stream plot?

조회 수: 7 (최근 30일)
Rubel Ahmed
Rubel Ahmed 2021년 7월 12일
댓글: Rubel Ahmed 2021년 8월 6일
I have a 2D domain which has diffrent width(X) and length(Y) as attached photo. Say the height Y=0.05 and width X=0.02;
I have each particle position array in X,Y and I know the corresponding velocity of the particle in U and V.
If I create meashgrid say
[X1,Y1] = meshgrid(0:0.005:0.02,0:0.005:0.05);
Then how I create the dimension of U and V equal to the dimension of X1 and Y1? So that I can plot
streamline(X1,Y1,U,V)
Please help,Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 12일
U1 = interp2(X, Y, U, X1, Y1);
V1 = interp2(X, Y, V, X1, Y1);
streamline(X1, Y1, U1, V1);
  댓글 수: 13
Walter Roberson
Walter Roberson 2021년 8월 5일
편집: Walter Roberson 2021년 8월 5일
You can do a bit better by calling stream2() yourself, see the first example at
The idea is that you would filter down your coordinates. For example break up into two blocks, one the left area and the other the bottom area, so that you avoid doing all that interpolation for the large part of your plot that is empty.
It might take a bit of work to figure out where the useful boundaries are given only the scattered data. One approach would be a crude 2d histogram to find out which parts are occupied.
By the way, I just opened a case recommending specific performance improvements to streamline(). I doubt we will see them before 2022 however.
Rubel Ahmed
Rubel Ahmed 2021년 8월 6일
I can plot the quiver plot on the lower bath region where the geometry filled with fluids by using the griddata function as attached figures. When I am again trying to plot the streamline by using the same interpolated data(data that used to plot the quiver plot), still no improvment. Do you khowwhats wrong now? Since my program can avoided the empty space of the L shape. Also, is it possible to add lines on the quiver plot?
My code is
AXX= ARPP(:,1); % Prticles x position with array size n by 1
AYY= ARPP(:,2); % Prticles y position with array size n by 1
UXX= gather(TRPV(:,1)); % Prticles x velocity component with array size n by 1
UYY= gather(TRPV(:,2)); % Prticles y velocity component with array size n by 1
for i = 1:40000
for j = 1
if AYY(i,j)< 0.01
X(i,j)=AXX(i,j);
Y(i,j)=AYY(i,j);
XU(i,j)=UXX(i,j);
YU(i,j)=UYY(i,j);
else
X(i,j)=0;
Y(i,j)=0;
XU(i,j)=0;
YU(i,j)=0;
end
end
end
X = X(X~=0);
Y = Y(Y~=0);
XU = XU(XU~=0);
YU = YU(YU~=0);
[X1,Y1] = meshgrid(-6*PDis:0.0006:0.01,-6*PDis:0.0006:0.01); % Total geometry is divided into gridpoints
U1 = griddata(X,Y,XU, X1, Y1);
V1 = griddata(X,Y,YU, X1, Y1);
figure(10)
% streamline(X1, Y1, U1, V1)
quiver(X1, Y1, U1, V1)
pbaspect([1 1.2 1])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by