Streamline plot does not make sense

조회 수: 3 (최근 30일)
Peisen Tan
Peisen Tan 2023년 10월 31일
편집: Cris LaPierre 2023년 11월 1일
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])

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 11월 1일
편집: Cris LaPierre 2023년 11월 1일
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개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by