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]; endend [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 onq1 = quiver(Xm, Ym, u, v, 0.5, 'color', 'r'); hold onq2 = quiver(Xm, Ym, - u, - v, 0.5, 'color', 'r'); hold onqdiag = quiver(Xm, Ym, u_diag, v_diag, 0.5, 'color', 'b'); hold onqdiag2 = quiver(Xm, Ym, - u_diag, - v_diag, 0.5, 'color', 'b'); hold offq1.ShowArrowHead = 'on';q2.ShowArrowHead = 'on';qdiag.ShowArrowHead = 'on';qdiag2.ShowArrowHead = 'on';axis equal
Best Answer