MATLAB Answers

How to arrainge data to use streamline?

3 views (last 30 days)
David Winthrop
David Winthrop on 13 Feb 2020
Commented: KSSV on 15 Feb 2020
Hello,
I have data exported from a finite element software that I want to use in MATLAB to plot streamlines. The format is
xc,yc,zc,vx,vy,vz
where xc, yc and zc are (M-by-1) vectors of the coordinates of the nodes. vx, vy and vz are the components of the velocity at those coordinate locations.
The help for streamline says the X, Y and Z inputs must be monotonic, but my vectors are not sorted. I think if I sort them to satisfy the monotonic condition then they will not match the vx, vy and vz sorting, and since it is very unlikely they will all sort the same way, there is no way to keep them meatched to the vx, vy and vz.
How can I get my data in a form that streamline can use?
Thanks

  0 Comments

Sign in to comment.

Answers (3)

KSSV
KSSV on 13 Feb 2020
I guess what you have is unstructured FEM mesh data. YOu need to convert it to grided data. You can do inteprolation using gridddata. Refer this link:

  0 Comments

Sign in to comment.


David Winthrop
David Winthrop on 13 Feb 2020
Edited: David Winthrop on 13 Feb 2020
I tried to use griddata but there are some results that MATLAB can't seem to find, such as the re-circulation zones. Here is the streamline plot from the FEA software. I have annotated to show the coordinate system used.
Here is the code I used. It reproduces some of the stream lines but not the re-circulation lines. Any idea if I am doing something wrong?
sf = xlsread('stream_dat2.csv');
f = min( sf(:,1:2), [], 1 ); %// XY grid starting points
t = max( sf(:,1:2), [], 1 ); %// XY endpoints
[X,Y] = meshgrid( linspace( f(1), t(1), 50 ), linspace( f(2), t(2), 50 ) ); %//grid
U = griddata( sf(:,1), sf(:,2), sf(:,3), X, Y );
V = griddata( sf(:,1), sf(:,2), sf(:,4), X, Y );
startx = [0,-0.001,-0.0014]; %// define streamline starting points
starty = [-0.002,0,-0.0024]; %//
S = streamline( X, Y, U, V, startx, starty );
set(S,'color','r','linewidth',4)
hold on
plot(sf(:,1),sf(:,2),'*')
axis equal
set(gca,'ydirection','reverse')
view([-90,90])
xlabel('X')
ylabel('Y')
I have attached the CSV file as well.

  1 Comment

KSSV
KSSV on 15 Feb 2020
Increase the number in linspace. You have taken only 50. Keep increasing it and check.

Sign in to comment.


David Winthrop
David Winthrop on 14 Feb 2020
Bumping in the hopes that someone can help.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags