MATLAB: How to plot vectors pointing outwards from origin in a 3D matrix

3dcoordinatesmatrixoutwardoutwardsplotquiver3spheresphericalvectorvectors

Something similar to the picture below. An origin point is specified and vectors are plotted outwards.
I need it in the format of three 3D matrices that each contain the component of the vector at the position. (Hx, Hy, Hz).
quiver3(X,Y,Z,Hx,Hy,Hz), ideally would plot something like the image below. (X,Y,Z are the positions, and Hx,Hy,Hz are vector components)

Best Answer

To anyone from the future, I answered my own question, as is often the case...
Using the spherical coordinate system
n = 32;
nc = round((n+1)/2);
vec = (1:n)-nc;
[x,y,z] = meshgrid(vec);
r = sqrt(x.^2 + y.^2 + z.^2);
psi = atan2(y,x);
theta = acos(z ./ r);
theta(isnan(theta)) = 0;
Mx = sin(theta).*cos(psi);
My = sin(theta).*sin(psi);
Mz = cos(theta);
quiver3(x,y,z,Mx,My,Mz)