MATLAB Answers

Create Streamlines with Curvilinear Grid

3 views (last 30 days)
Cas Cas
Cas Cas on 3 Aug 2021
Commented: Cas Cas on 16 Aug 2021
I have a curvilinear grid with [x,y,z] coordinates and location has [u,v,w] components representing a flow field.
I'm able to plot quiver plots and create animations of the vector fields but I'm trying to incorporate streamlines as well, and this is where I'm having trouble. I suspect the issue is my grid being curvilinear rather than rectilinear and uniform (although the help for streamline() suggests that points do not need to be uniform, so maybe I'm wrong).
I've been getting a couple of errors:
First, when I have NaNs in the data
Error using matlab.internal.math.interp1
The sample points must be finite.
Error in interp1 (line 154)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in stream2 (line 62)
sxi=interp1(xx(:),1:szu(2),sx(k));
Error in streamline (line 62)
verts = stream2(x,y,u,v,sx,sy,options);
Alright, it's easier to work with NaNs but I can remove those from the data. I turn the [x,y,z] points that are NaN into zeroes and make sure my matrix and vector lengths remain okay. (I need an auto scale factor in the quiver plot now, though, which is a bit annoying).
Second, when I fix this, I get the following
Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.
Error in interp1 (line 154)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in stream2 (line 62)
sxi=interp1(xx(:),1:szu(2),sx(k));
Error in streamline (line 62)
verts = stream2(x,y,u,v,sx,sy,options);
Perhaps I'm interpreting this wrong, but when I check my startx and starty points, they are ascending and unique points.
I'm attaching an image of my grid: black dots represent the grid points, green arrows represent where [u,v,w] data exists, and red crosses are my starting points for my streamlines.
I'm also attaching a dataset: this dataset is a subset of my full grid for simplicity. The grid and vector fields do contain NaN values. In an attempt to circumvent the errors I'm getting, I turn all NaNs to 0. I would like to delete them altogether but then I would no longer have gridded data. Turning them to zeros though means that I need the scale factor in the code.
I've also attached my code (it's also how I made the figure).
Note for now until I get this going I'm focussing on 2D (i.e. x, y, u,and v).
  2 Comments
Cas Cas
Cas Cas on 4 Aug 2021
@KSSV Shoot. Thanks for noticing. I had updated the .mat file but forgotten to replace it here.
Updated now. 22 x 31 grid.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 4 Aug 2021
load('streamline_help.mat')
x = gridx_subset ;
y = gridy_subset ;
u = u_subset ;
v = v_subset ;
% Remove nans
idx = ~isnan(x) ;
x = x(idx) ;
y = y(idx) ;
u = u(idx) ;
v = v(idx) ;
% convert data to grid data
m = 30 ; n = 30 ;
xi = linspace(min(x),max(x),m) ;
yi = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(xi,yi) ;
U = griddata(x,y,u,X,Y) ;
V = griddata(x,y,v,X,Y) ;
figure(1)
streamline(X,Y,U,V,X(1:2:end,1:2:end),Y(1:2:end,1:2:end))
  3 Comments
Cas Cas
Cas Cas on 16 Aug 2021
Alright then. Thanks for your help. My question is answered, though my specific need isn't entirely addressed, but the workout we have will have to suffice, so I am accepting the answer. Cheers.

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!