Ploting streamline with vector's module on line.

4 views (last 30 days)
% 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 Comments
Dyuman Joshi
Dyuman Joshi on 18 Oct 2023
Are you sure you want to plot streamlines and not contours?
泽江
泽江 on 19 Oct 2023
Yes, streamlines with Direction, and the diffrent Magnititude presented along the line. Diffrent scales of arrows to describe the magnititude could be all right.

Sign in to comment.

Accepted Answer

Sam Chak
Sam Chak on 19 Oct 2023
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 Comments
Sam Chak
Sam Chak on 21 Oct 2023
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')
泽江
泽江 on 24 Oct 2023
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!

Sign in to comment.

More Answers (0)

Categories

Find more on Language Support in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!