How to create continuous points and plot in quiver

10 visualizaciones (últimos 30 días)
Tina Hsiao
Tina Hsiao el 11 de Abr. de 2021
Respondida: Darshak el 3 de Mzo. de 2025
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

Respuestas (1)

Darshak
Darshak el 3 de Mzo. de 2025
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.

Categorías

Más información sobre Vector Fields en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by