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 comentarios

Dyuman Joshi
Dyuman Joshi el 18 de Oct. de 2023
Are you sure you want to plot streamlines and not contours?
泽江
泽江 el 19 de Oct. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

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 comentarios

泽江
泽江 el 19 de Oct. de 2023
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 el 19 de Oct. de 2023
Could you please attach the data you are working with?
泽江
泽江 el 19 de Oct. de 2023
Sorry, it's too big even after zipping....
Dyuman Joshi
Dyuman Joshi el 20 de Oct. de 2023
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?
泽江
泽江 el 21 de Oct. de 2023
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!
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')
泽江
泽江 el 24 de Oct. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 18 de Oct. de 2023

Comentada:

el 24 de Oct. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by