Filled velocity contours for series of data?

조회 수: 1 (최근 30일)
Hadi
Hadi 2014년 5월 6일
답변: Prateekshya 2024년 10월 23일
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
Sara
Sara 2014년 5월 6일
Can you post your data and the matlab code you are using?

댓글을 달려면 로그인하십시오.

답변 (1개)

Prateekshya
Prateekshya 2024년 10월 23일
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!

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by