Filled velocity contours for series of data?

1 view (last 30 days)
Hadi
Hadi on 6 May 2014
Answered: Prateekshya on 23 Oct 2024 at 2:49
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 Comment
Sara
Sara on 6 May 2014
Can you post your data and the matlab code you are using?

Sign in to comment.

Answers (1)

Prateekshya
Prateekshya on 23 Oct 2024 at 2:49
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.
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:
  • 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:
You can modify the code according to your requirements.
I hope this helps!

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!