Ploting streamline with vector's module on line.

% when using :
streamline(Velocity_x_1,Velocity_y_1,linspace(1,Nx,Ny),linspace(1,1,Ny));
hold on
streamline(Velocity_x_1,Velocity_y_1,linspace(1,Nx,Ny),linspace(Ny,Ny,Ny));
hold on
streamline(Velocity_x_1,Velocity_y_1,linspace(1,1,Ny),linspace(1,Ny,Ny));
hold on
streamline(Velocity_x_1,Velocity_y_1,linspace(Nx,Nx,Ny),linspace(1,Ny,Ny));
hold on
% I plot the streamline of the fluid field by 4 sides of the field.
% however, the result are not good of course.
% Since I have no knowledge of the field, I didn't know how to draw the
% effective streamline by this function. And I also want to know how to add
% the module of the vectors on streamlines just like the contourlines in
% geography textbooks. Thanks a lot!
% the result is:
% what I want is like:
% But with direction like vector lines.

2 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 18 日
Are you sure you want to plot streamlines and not contours?
泽江
泽江 2023 年 10 月 19 日
Yes, streamlines with Direction, and the diffrent Magnititude presented along the line. Diffrent scales of arrows to describe the magnititude could be all right.

サインインしてコメントする。

 採用された回答

Sam Chak
Sam Chak 2023 年 10 月 19 日

0 投票

Can you check if the following are what you want?
spacing = 0.2;
x = -2:spacing:2;
y = -2:spacing:2;
[X, Y] = meshgrid(x,y);
Z = X .* exp(-X.^2 - Y.^2);
figure(1)
level = 10;
contour(X, Y, Z, level, 'ShowText', 'on')
figure(2)
[DX,DY] = gradient(Z, spacing);
quiver(X, Y, DX, DY), axis([-2 2 -2 2])
figure(3)
contour(X, Y, Z, level, 'ShowText', 'on'), hold on
quiver(X, Y, DX, DY), axis([-2 2 -2 2])

7 件のコメント

泽江
泽江 2023 年 10 月 19 日
Thanks for answering, @Sam Chak, but it's maybe not what I want, actually I tried some method, this is my present result:
What I want to do now is adding the direction notation for lines I elected. I tried to control the streamline objects to change the properties of them so I can add markers in which place I want. But I didn't know how to manuplate the objects. Say:
s1=streamline(Velocity_x_4,Velocity_y_4,linspace(1,1,Ny/10),linspace(1,Ny,Ny/10));
hold on
s2=streamline(Velocity_x_4,Velocity_y_4,linspace(Nx,Nx,Ny/10),linspace(1,Ny,Ny/10));
hold on
for i=1:length(s1)
s1(i).Color='k';
end
for i=1:length(s2)
s2(i).Color='k';
end
when I create this two objects, I can't change the properties of the components of this two objects. For example, I want to change the markers of the mid point of streamline 1 from 'none' to '^' which means triangles, but I found I can only change all the points' properties like markers.
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 19 日
Could you please attach the data you are working with?
泽江
泽江 2023 年 10 月 19 日
Sorry, it's too big even after zipping....
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 20 日
Maybe a sample of the data rather than all of it?
I assume you got this data from a simulation. Did you use Ansys Fluent?
泽江
泽江 2023 年 10 月 21 日
Yes it's a simulation, but I got this by my C++ codes. And I found the compromised method. I used contour without number and lines to show magnititude only by colors. Then I use quiver to draw the vectors which are all normallized so the arrow's size could be the same. By this method, I seperate the direction and magnititude of vectors. Although this is not that good, it's all right. Thanks for your patient helping these days!
Sam Chak
Sam Chak 2023 年 10 月 21 日
No worries @泽江. You can show what you've plotted using the contour/quiver approach and then share your expectations with us. The plotting features in MATLAB are highly customizable. However, my plotting skills are only so-so. Perhaps @Dyuman Joshi can provide advice and a solution in his answer.
Considering the density of lines, I can imagine your data is quite big. Nevertheless, you can extract a portion of the data, say 20% to 30%. Here's an example of how to extract 10% of the data. We're looking forward to seeing Velocity_x_new and Velocity_y_new.
% Original Data with 101 points
x = linspace(0, 10, 101);
y = x.^2;
plot(x, y, '.'), hold on
% Extract 10% from the data
percent = 10;
stepSize = percent/100*(numel(x) - 1)
stepSize = 10
xNew = x(1:stepSize:end)
xNew = 1×11
0 1 2 3 4 5 6 7 8 9 10
c = ismember(x, xNew); % check if Set xNew is a subset of Set x
idx = find(c); % find indices of the subset ⊂
yNew = y(idx)
yNew = 1×11
0 1 4 9 16 25 36 49 64 81 100
plot(xNew, yNew, 'o', 'MarkerSize', 11, 'LineWidth', 2), grid on
xlabel('x'), ylabel('y')
泽江
泽江 2023 年 10 月 24 日
Thanks a lot! This is also an useful technique for me! Sometimes I do need a rougher data with interpolation data. For example, the field may cost more time to converge if you increase the grid number. But with the rougher grid's data, I can set a good initial condition then make it conveged more quickly. That's very helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLanguage Support についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 10 月 18 日

コメント済み:

2023 年 10 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by