Hi everybody,
I have my coordinate data -X and Y vectors- and my velocity vectors U and V all being the same size. I would like to plot path lines of my fluid particles which are flowing through a porous medium. With these 4 known vectors any suggestions on how to do that??
Thanks in advance.

 Accepted Answer

Can you show the exact code you tried when calling quiver and streamline? And the specific error you see? Repeated x- and y-coordinates due to data being on a grid is expected by streamline. I assume you tried something along the lines of this?
W = load('wind');
xlim = [min(W.x(:)) max(W.x(:))];
ylim = [min(W.y(:)) max(W.y(:))];
sx = rand(100,1)*diff(xlim) + xlim(1);
sy = rand(100,1)*diff(ylim) + ylim(1);
quiver(W.x(:,:,1), W.y(:,:,1), W.u(:,:,1), W.v(:,:,1));
hold on;
hl = streamline(W.x(:,:,1), W.y(:,:,1), W.u(:,:,1), W.v(:,:,1), ...
sx(:), sy(:));
set(hl, 'color', 'r');

5 Comments

Hey thanks a lot,
Here how it looks for quiver
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Lx=sqrt(1+qx.^2);
Ly=sqrt(1+qy.^2);
figure
quiver(X_plot(:,1),X_plot(:,2),qx./Lx,qy./Ly)
title('Direction field numerical')
axis([-2 12 -4 4])
title('Potential Flow Through Coarse adapted mesh')
%%%%%%%%%%%%%%%%%%%%%
Lx and Ly just to normalise the arrows on quiver plot. Attention that all X_plot (:,1) X_plot (:,2) qx and qy are vectors.
For streamlines I tried
%%%%%%%%%%%%%%%%%%%%%%%%
figure
[x1 y1]=meshgrid(X_plot(:,1),X_plot(:,2));
streamline(x1,y1,diag(qx),diag(qy),0,-3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Attention-->plot streamline I need to give matrices and what I have is vectors; this is why I tried to use "mesh grid" and "diag". Since I have no functional description of qx and qy I could not figure out how to provide them in matrix form.
And got error saying "The values of X should be distinct".
When I tried to defeat the error message with unique function the precision of unique did me no good.
Hope I am clear and my question makes sense.
It would be helpful to see the full error message (including function, line numbers, etc).
I'm assuming that X_plot is a 2-column array of x- and y-coordinates, and qx and qy are vectors. To use streamline, you need to convert this scattered data onto a grid. So you're sort of on the right track with meshgrid, though not diag. Exactly how you grid the data depends on the locations of the data points. If they're truly scattered, scatteredInterpolant is probably the best route.
x = linspace(min(X_plot(:,1)), max(X_plot(:,1)), 10);
y = linspace(min(X_plot(:,2)), max(X_plot(:,2)), 10);
[xg, yg] = meshgrid(x, y);
Fx = scatteredInterpolant(X_plot(:,1), X_plot(:,2), qx);
Fy = scatteredInterpolant(X_plot(:,1), X_plot(:,2), qy);
qxg = Fx(xg,yg);
qyg = Fy(xg,yg);
quiver(X_plot(:,1), X_plot(:,2), qx, qy);
hold on;
quiver(xg, yg, qxg, qyg, 'r');
hl = streamline(xg, yg, qxg, qyg, 0, -3);
set(hl, 'color', 'g');
The quiver plots were just there for reference, so you could see whether your gridding was replicating the major features of your flow field.
As for the streamlines, you've specified a starting location of x=0, y=-3, and there happens to be near-0 flow at that location, so your streamline is very short. Try choosing some starting points throughout the domain to get more streamlines.
To get a better picture, you'd want to calculate the actual streamfunction of your domain, then contour it. I'm actually rather surprised to find that not only is there not a streamfunction calculation available in Matlab, there also doesn't seem to be any easy-to-find offerings on the file exchange. The functions I rely on come from an external toolbox and are specific to oceanography.
Kelly thanks for your precious help, now I understand how it works and now streamlines look in the way that I want.
You asked for "pathlines", but this solution gives "streamlines". Note that they are different. Streamlines are instantaneous tangent lines, i.e. massless particles in a steady field. Pathlines are time-dependent and can be used in unsteady fields for inertial particles too. You may want to change the title of the question to reflect that if "streamlines" were indeed what you needed.

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 16 Jun 2014

1 vote

I do not know exactly what you want to do, however at least one of the Vector Fields plotting functions will likely do what you want.

4 Comments

Thank you very much. I already have a quiver plot which looks like attached. What I actually wanted was plotting streamlines but my X and Y position vectors are coming from my mesh data and have repetitive data. I used unique function and then mesh grid to be able to use at the end "streamline" function of Matlab. But the precision of unique function is not helping me after I used it and used mesh grid I could not use 'streamline' with en error message saying that X and Y has repetitive data.
So after all these now I want to plot at least the path lines i.e the trajectory of a fluid particle.
Do not know if I make myself clear. Hope you have some suggestions for me.
The unique function does not work well with floating point data because of inherent floating-point approximation error. I suggest you not use it with those data.
The contour and surf plots (with quiver3 may also do what you want, but since I don’t know your data, I can only suggest you experiment with them until you get the result you want.
The only other options I can think of are plot and plot3. They are relatively simple, but they may work in your applicataion. (You may have to segment your data to use the line plots.)
Thanks a lot, I will consider your suggestions and share here the results :)

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!