How to create continuous points and plot in quiver

조회 수: 10 (최근 30일)
Tina Hsiao
Tina Hsiao 2021년 4월 11일
답변: Darshak 2025년 3월 3일
Hello, I would like to seek your help. I had created discrete points and plot vector field by using the quiver function. Now, I would like to create continuous points which are in the same range (0 to 300), and the result of vector field should be the same as discrete points.
my code as below,
clear all; close all; clc
% discrete points
v = 0:25:300;
[x,y] = meshgrid(v);
z = -cos(x).*(-x.^2 - y.^2)*1e-4;
[px,py] = gradient(z);
figure(1)
quiver(x,y,px,py)
hold off

답변 (1개)

Darshak
Darshak 2025년 3월 3일
Hi @Tina Hsiao,
When working with data, continuous data is typically represented by using finer discrete data points. To create a quiver plot that aligns with your use case, you might find the following sample code useful, as it effectively simulates continuous data, in this code, the following steps are undertaken:
  • A finer grid is defined by generating more granular data points.
  • Use “interp2” for interpolation of gradient data over this newly established grid.
  • The interpolated vector field is then visualized using the “quiver function.
v = 0:25:300;
[x, y] = meshgrid(v);
z = -cos(x).*(-x.^2 - y.^2) * 1e-4;
[px, py] = gradient(z);
% Continuous points
v_fine = 0:1:300; % Create a finer grid
[x_fine, y_fine] = meshgrid(v_fine);
% Interpolate the vector field
px_fine = interp2(x, y, px, x_fine, y_fine, 'cubic');
py_fine = interp2(x, y, py, x_fine, y_fine, 'cubic');
% Plot the continuous vector field
figure(2)
quiver(x_fine, y_fine, px_fine, py_fine)
title('Continuous Vector Field')
xlabel('x')
ylabel('y')
You can explore the “interp2” and “quiver” function’s documentation for a better understanding of the same.

카테고리

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