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 Center および File ExchangeVector Fields についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by