MATLAB Answers

Issue plotting streamlines (input in ascending order)

2 views (last 30 days)
Hi all,
I am having an issue plotting some streamlines. I get an error when I attempt to plot my streamlines because it uses interp1 and one of my inputs to streamline is not in "ascending order". I have attached my code and data file. The streamlines should be going from left to right like the vectors in the quiver plot.
Quiver plot looks like this:
Error message is this:
What do I need to do with the inputs to streamline() to makes this work properly?
clc;clear;close all;
%Set plot stuff:
% set(0,'DefaultLineColor',[1,1,1])
% set(0,'DefaultTextInterpreter','latex')
runname = 'M.25_0Y_A';
%% Load data
Uavg(Uavg==0) = NaN; % Set null data to NaN
Vavg(Vavg==0) = NaN; % Set null data to NaN
Xi = sort(X(:,1));
Yi = sort(Y(1,:))';
%% Create the combination of xq and yq
[Xq, Yq] = meshgrid(Xi,Yi);
% Interp the data if the x and y data in the file is not in a grid
Uq = rot90(Uavg);
Vq = rot90(Vavg);
%% probe walls (Need rotate these eventually)
ytip = 4.18-1; % Bottom left vertice of left probe wall
xtip = -7.703; % Bottom left vertice of left probe wall
width = 12.7; % mm
height = 1; % mm
gap = 3; % mm - Distance between probe walls (left end of the walls)
%% New coordinates (origin will be at hte probe tip)
xcenter = xtip; % X-center point of probe tip
ycenter = ytip-height; % Y-center point of probe tip
xtip = xtip-xcenter; % Bottom left vertice of left probe wall
ytip = ytip-ycenter; % Bottom left vertice of left probe wall
Xq = Xq+ycenter;
Yq = Yq-xcenter;
%% Plot vectors, probe walls, and streamlines
fig = figure('Renderer', 'painters', 'Position', [1300 10 947 900])
quiver(Yq,-Xq,Vq,-Uq, 1);%, 'LineWidth',2) % Plot vectors
hold on;
yline(0);xline(0); hold on % Plots probe centerlines
l = title({'test_line'}, 'Interpreter', 'none');
title(['Averaged Velocities and Streamlines (',runname,')'])
% % Plot probe walls
xlabel('x (mm)')
ylabel('y (mm)')
s = 0.10;
starty = -2.5:s:2.5;
startx = (min(min(Yq))+.25)*ones(size(starty));
%% Plot Streamlines
% hgridinterp = streamline(Yq,Xq,Vq,Uq,startx,starty); hold on;
hgridinterp = streamline(Yq,-Xq,Vq,-Uq,startx,starty); hold on;

Accepted Answer

Addison Collins
Addison Collins on 13 Aug 2021
Edited: Addison Collins on 13 Aug 2021
I changed the order in which I created the meshgrid, that fixed things.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by