Plotting streamlines from a dataset (x,y,u,v)
Show older comments
I am attempting to plot streamlines from some location and velocity data provided in a .txt. I have x, y, u, v where x & y are positions and u & v are their corresponding velocity components. I would like to plot streamlines and vectors of this data. Everything is in vector form with 345600 elements. I have manually determined I have 640 unique x values and 540 unique y values. Essentially there is matrix that can be made from this in the form of (640 x 540). I attempted utilizing meshgrid(x,y) and meshgrid(u,v). But this led to issues due to the resulting size when you mesgrid two vectors of 345600.
I have a poor understanding of how exactly meshgrid works. Given the nature of the table I am provided, is it necessary to meshgrid (x, y) and meshgrid (u, v)? Or should I reshape the x, y, u, & v vectors in order to get matrices that can be used in streamlines(x,y,u,v,startx,starty)?
Note: If this code does require a meshgrid for x ,y, u, & v, then it will almost certainly be necessary to reduces the resolution of the data to make calculations. Perhaps only using every 5th value. Also, I think the resolution will cause the arrows and streamlines too be too close together (?).
clear all; close; clc;
ntot = 345600;
n1 = 100000; n2 = 101000;
filename = 'run27_avg';
data = readmatrix(strcat('.\average_velocities\',filename,'.txt'));
x = data(:,1);
% [fc,fia,fic]=unique(x)
% length(unique(x,'rows'))
x = x(n1:n2, 1);
y = data(:,2);
y = y(n1:n2, 1);
[x,y] = meshgrid(x,y);
u = data(:,3);
u = u(n1:n2, 1);
v = data(:,4);
v = v(n1:n2, 1);
[u,v] = meshgrid(u,v);
figure()
quiver(x,y,u,v)
startx = 0.1:0.1:1;
starty = ones(size(startx));
streamline(x,y,u,v,startx,starty)
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!