# Plot arrowheads pointing inward to a center with quiver

3 views (last 30 days)
Szu-Ting Kuo on 14 Sep 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
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
axis equal

Madhav Thakker on 18 Sep 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.