Plot arrowheads pointing inward to a center with quiver
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Szu-Ting Kuo
il 14 Set 2020
Risposto: Madhav Thakker
il 18 Set 2020
Greetings,
I was trying to plot double arrowheads with quiver in MATLAB, with each double arrowhead pointing "inward" to the center of each node.
However, the quiver function only outputs the arrowheads pointing outward. Below is the code I've been working on. Would be great if someone helps me fix this. Thanks!
%%
close all; clear
%%
% First part: construct the meshgrid
% ref: https://www.mathworks.com/matlabcentral/answers/452126-plot-coordinates-in-the-center-of-grid
NX = 11 ; NY = 11 ;
nel = (NX-1)*(NY-1) ; % Number of elements in the surface
nnel = 4 ; % Number of nodes per element
nodes = zeros(nnel, nel) ; % Initialize nodal connectivity matrix
count = 0 ;
for i = 1:NX-1
for j = 1:NY-1
l = (j-1)*(NX)+i ;
count = count+1 ;
nodes(:,count) =[l l+1 l+NX+1 l+NX];
end
end
[X,Y] = meshgrid(1:NX, 1:NY) ;
X = X(:) ; Y = Y(:) ;
Xm = mean(X(nodes)) ;
Ym = mean(Y(nodes)) ;
% Second part: quiver calculation in polar coordinates
r = sqrt(Xm.^2 + Ym.^2); % r in function of (x, y)
theta = atan2(Ym, Xm); % theta in function of (x, y)
u = r.*cos(theta); % x component of the vector field
v = r.*sin(theta); % y component of the vector field
u_diag = r.*cos(theta + pi/2);
v_diag = r.*sin(theta + pi/2);
figure(1)
plot(X(nodes),Y(nodes),'k') ; hold on
q1 = quiver(Xm, Ym, u, v, 0.5, 'color', 'r'); hold on
q2 = quiver(Xm, Ym, - u, - v, 0.5, 'color', 'r'); hold on
qdiag = quiver(Xm, Ym, u_diag, v_diag, 0.5, 'color', 'b'); hold on
qdiag2 = quiver(Xm, Ym, - u_diag, - v_diag, 0.5, 'color', 'b'); hold off
q1.ShowArrowHead = 'on';
q2.ShowArrowHead = 'on';
qdiag.ShowArrowHead = 'on';
qdiag2.ShowArrowHead = 'on';
axis equal
0 Commenti
Risposta accettata
Madhav Thakker
il 18 Set 2020
Hi Szu-Ting,
I understand that you want to change the direction of arrowheads to point inwards. The current quiver-properties do not allow for any such feature. I have raised an enhancement request for the same.
Hope this helps.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!