Streamline plot does not make sense
3 views (last 30 days)
Show older comments
Hi all, I am trying to plot the streamline in matlab, its a wind trajectory involving 2 D wind speed (u and w), on 5 different layers above the water surface. Y axis is the height above water surface and x axis is the phase of the water waves below. The ideal plot should look like the quiver plot on the right hand side, but the streamline plot is very weird, and it did not even cover the whole range of either x or y axis. The starting points of the streamlines are 9 degrees phase at each height. I am not sure if there is anything wrong with the code, please help and thanks so much! Here are the code and the graphs:
close all
clear all
phase_long=[9 27 45 63 81 99 117 135 153 171 189 207 225 243 261 279 297 315 333 351]
startx = ones(1,5)*9;
starty = [.10, .15,.25,.35,.45];
[x,y] = meshgrid(phase_long,starty);
u_with_mean = 5*ones(5,20);
for i = 1:5
w_with_mean(i,:) = 3*(-cos(phase_long));
end
subplot(1,2,2)
h2=quiver(u_with_mean,w_with_mean,0);
yticks([])
xticks([])
set(h2,'AutoScale','on', 'AutoScaleFactor', .5)
subplot(1,2,1)
streamline(x,y,u_with_mean,w_with_mean,startx,starty)
ylim([.05 .50])

0 Comments
Accepted Answer
Cris LaPierre
on 1 Nov 2023
Edited: Cris LaPierre
on 1 Nov 2023
I think the issue becomes more clear if you create your quiver plot using the following syntax: quiver(X,Y,U,V)
phase_long=[9 27 45 63 81 99 117 135 153 171 189 207 225 243 261 279 297 315 333 351];
startx = ones(1,5)*9;
starty = [.10, .15,.25,.35,.45];
[x,y] = meshgrid(phase_long,starty);
u_with_mean = 5*ones(5,20);
for i = 1:5
w_with_mean(i,:) = -3*cos(phase_long);
end
quiver(x,y,u_with_mean,w_with_mean,1)
Now let's overlay your streamlines, adding a marker to show where they start.
hold on
scatter(startx,starty)
streamline(gca,x,y,u_with_mean,w_with_mean,startx,starty)
hold off
xlim([9,30])
legend
By zooming in, you'll see that they follow the trajectory at 9. I think your grid is too spaced out for your streamlines. Try refining the grid a little.
phase_long=9:2:351;
[x,y] = meshgrid(phase_long,0:.05:1);
u_with_mean = 5*ones(size(x));
w_with_mean = -3*cos(repmat(phase_long,size(x,1),1));
figure
quiver(x,y,u_with_mean,w_with_mean,1)
% Zoom in to see what is happening
xlim([9 20])
% now add streamlines
hold on
streamline(gca,x,y,u_with_mean,w_with_mean,startx,starty)
hold off
0 Comments
More Answers (0)
See Also
Categories
Find more on Vector Fields 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!
