Filled velocity contours for series of data?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi there,
I have a series of data x,y,vx and vy. x and y being dimensions with x=[1:m] and y=[1:n]. vx and vy are velocity components with vx=[1:m] and vy=[1:n]. I can plot the vectors using quiver. What I'm wondering about is how to plot filled velocity contours. I used contourf, but it's not working. Would anybody please help me to do this. Thanks Hadi
1 comentario
Respuestas (1)
Prateekshya
el 23 de Oct. de 2024
Hello Hadi,
To create filled velocity contours from velocity components
and
, you first need to compute the magnitude of the velocity vector at each point. Once you have the velocity magnitudes, you can use contourf to plot the filled contours.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797465/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797470/image.png)
Here is a step-by-step guide on how to achieve this in MATLAB:
- Compute the Velocity Magnitude: Calculate the magnitude of the velocity vector at each point using the formula:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797475/image.png)
- Use contourf to Plot the Filled Contours: With the computed magnitudes, use contourf to create the contour plot.
% Sample data
m = 100; % Number of points in x-direction
n = 80; % Number of points in y-direction
x = linspace(1, m, m);
y = linspace(1, n, n);
% Example velocity components
[vx, vy] = meshgrid(linspace(-1, 1, m), linspace(-1, 1, n));
% Compute velocity magnitude
velocity_magnitude = sqrt(vx.^2 + vy.^2);
% Plot filled contours
figure;
contourf(x, y, velocity_magnitude, 20); % '20' specifies the number of contour levels
colorbar; % Display a colorbar
title('Filled Velocity Contours');
xlabel('X Dimension');
ylabel('Y Dimension');
% Optionally, overlay quiver plot
hold on;
quiver(x, y, vx, vy, 'k'); % 'k' specifies black color for quiver arrows
hold off;
You will be able to see the following plot after executing this code in MATLAB:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1797480/image.png)
You can modify the code according to your requirements.
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Vector Fields en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!