MATLAB: Plotting streamlines from velocity components

streamlinesvelocity components

I am having trouble creating streamlines in MATLAB. I have: (1) x,y,z coordinates and (2) velocity components (Vx, Vy, Vz).
I have no trouble plotting the quiver (arrow) plot, but I cannot figure out the streamlines.
Any help would be greatly appreciated.
Thanks,
-Mike

Best Answer

Michael,
I've got some code below that plots slices and streamlines for your data but the data itself is odd. It looks like you've got an impeller blowing into a tank but the velocity vector that's coming out of it is normal to the impeller. However, that's what the quiver arrows show so the streamlines follow the arrows. So at least, you can now look at your streamlines as you work on the velocities (if necessary.
Good luck!
clearvars
load 'velocity components.mat'
mag_V = sqrt(Vx.^2 + Vy.^2 + Vz.^2);
% Filtering out zero velocity walls.
index = mag_V > 0.1;
xx = x(index);
yy = y(index);
zz = z(index);
Vxx = Vx(index);
Vyy = Vy(index);
Vzz = Vz(index);
FVx = scatteredInterpolant(xx,yy,zz,Vxx,'linear','none');
FVy = scatteredInterpolant(xx,yy,zz,Vyy,'linear','none');
FVz = scatteredInterpolant(xx,yy,zz,Vzz,'linear','none');
% This is a very ugly grid for your problem but it works.
% A cylindrical grid would probably be more resource efficient
elements = 40; % how many subdivisions per dimensions.
% Mind you, this is 3D. Total memory gets large fast
[X3, Y3, Z3] = meshgrid(linspace(min(x),max(x),elements),...
linspace(min(y),max(y),elements),...
linspace(min(z),max(z),elements));
V3x = FVx(X3,Y3,Z3);
V3y = FVy(X3,Y3,Z3);
V3z = FVz(X3,Y3,Z3);
mag_V3 = sqrt(V3x.^2 + V3y.^2 + V3z.^2); % velocity vector magnitude
starting_x = zeros(5,5); % starting points for streamlines
[starting_y, starting_z] = meshgrid(linspace(-0.005,.005,5), ...
linspace(-0.005,.005,5));
figure(1)
clf
plot3(x,y,z,'.k','MarkerSize',4);
hold on
quiver3(x,y,z, Vx,Vy,Vz);
h = slice(X3,Y3,Z3,mag_V3,[],0,-0.02:.02:0);
set(h,'EdgeColor','w','FaceAlpha',0.75');
h = streamline(X3,Y3,Z3,V3x,V3y,V3z,starting_x,starting_y,starting_z);
set(h,'LineColor','r','LineWidth',4);
axis equal
grid on
hold off