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일

0 개 추천

U1 = interp2(X, Y, U, X1, Y1);
V1 = interp2(X, Y, V, X1, Y1);
streamline(X1, Y1, U1, V1);

댓글 수: 13

Rubel Ahmed
Rubel Ahmed 2021년 7월 12일
However, what is the X and Y, U ,V and what are the array size ? because the array size of X1 and Y1 is not equal to X,Y,U,V. I guess the array size should be same to interpolate.
Walter Roberson
Walter Roberson 2021년 7월 13일
You wrote,
"I have each particle position array in X,Y and I know the corresponding velocity of the particle in U and V."
I deduced from that that X and Y and U and V are 2D arrays that are all the same size, and that what you are trying to do is resample the 2D arrays at locations X1, Y1 (same size as each other but different size than X, Y, U, V)
Do you instead have the case where X, Y, U, V are vectors of scattered data, and the question is how to interpolate the scattered data into a regular 2D array?
Because if so, see griddata()
Rubel Ahmed
Rubel Ahmed 2021년 7월 13일
@Walter Roberson Thanks, I am really sorry if I confused you. let me clear more specifically
Say X= [ 1 2 3 5 7 ] % all particle x position,dimension/array size (1 by 5)
Y= [ 2 8 3 6 7 ] % all particle y position,dimension/array size (1 by 5)
U= [5 4 3 1 5 ] % all particle x velocity,dimension/array size (1 by 5)
V= [3 6 3 2 8 ] % all particle y velocity,dimension/array size (1 by 5)
Okay, now assume that these 5 particles located within the above geometry i.e problem doman.
Now, How I will draw the streamlines ? Thanks
X = [ 1 2 3 5 7 ]/200;
Y = [ 2 8 3 6 7 ]/200;
U = [ 5 4 3 1 5 ];
V = [ 3 6 3 2 8 ];
[X1,Y1] = meshgrid(0:0.005:0.02,0:0.005:0.05);
U1 = griddata(X, Y, U, X1, Y1);
V1 = griddata(X, Y, V, X1, Y1);
streamline(X1, Y1, U1, V1)
Rubel Ahmed
Rubel Ahmed 2021년 7월 14일
편집: Walter Roberson 2021년 7월 14일
@Walter Roberson thanks, I have rewrite the code lime this
[X1,Y1] = meshgrid(0:0.000049:0.02,0:0.000049:0.1);
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
U1 = griddata(AXX,AYY,UXX, X1, Y1);
V1 = griddata(AXX,AYY,UYY, X1, Y1);
figure(25)
streamline(X1, Y1, U1, V1)
Ths plot is not creating any figure ven I am not getting any error. Do you know what is/are the possible reasons?
Walter Roberson
Walter Roberson 2021년 7월 14일
편집: Walter Roberson 2021년 7월 14일
I would check min(AXX), max(AXX) against 0 to 0.02, and min(AYY), max(AYY) against 0:0.1, and check nnz(isnan(U1)), nnz(isnan(V1))
And of course nnz(U1), nnz(V1) to check whether maybe all of U1 and V1 ended up 0 somehow.
Rubel Ahmed
Rubel Ahmed 2021년 8월 3일
I have checked nnz(U1), nnz(V1) . Seems like ok since only few value are zero.
min(AXX), max(AXX) against 0 to 0.02 is okay. Min(AXX)= 0 and max(AXX)=0.02, Also same for the other y axis. What is the point of checking nnz(isnan(U1)), nnz(isnan(V1)) ?
still getting no error with empty figure. What is/are the possible reasons? Thanks again.
Walter Roberson
Walter Roberson 2021년 8월 3일
편집: Walter Roberson 2021년 8월 3일
nnz(isnan(U1)), nnz(isnan(V1)) is to detect the case where U1 or V1 are nan, since in such cases MATLAB cannot plot for that location.
Is it possible for you to attach your data as a .mat for testing?
Rubel Ahmed
Rubel Ahmed 2021년 8월 5일
@Walter Roberson Thanks !!!
plz find the attached data. Hope you can help me with this.
Walter Roberson
Walter Roberson 2021년 8월 5일
편집: Walter Roberson 2021년 8월 5일
Your data exists in a sort of an sidewise L shape near the boundaries, with a thin rise on the y axes that is about 1/40 of the thickness of the width you are trying to streamline; the bottom of the L is about 1/10 of the height you are trying to streamline and extends about 1/2 way across. Sort of like
* |
* |
* |
* |
************** |
************** |
Because of this, the streamline process spends a lot of time trying to interpolate NaN values. Only approximately 6% of the streamlines are non-nan, because most of where you are trying to plot is outside of where the data is defined for.
Rubel Ahmed
Rubel Ahmed 2021년 8월 5일
@Walter Roberson thanks. So, is it possible to plot the streamlines only on the bath domain i.e. lower bath domain where the bath is mostly filled with liquid.
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개)

카테고리

도움말 센터File Exchange에서 Vector Fields에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2021년 7월 12일

댓글:

2021년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by