This should be a really simple question, but for some reason I'm getting unreasonably confused and the Matlab documentation isn't helping.
Given a uniform grid of coordinates (x_i,y_j,z_k)
, I want to make a 3-dimensional array F
in Matlab such that F(i,j,k)=f(x_i,y_j,z_k)
. The following is obviously incorrect:
x=linspace(-1,1,100) % uniform mesh on [-1,1]^3
[X,Y,Z]=meshgrid(x);
f=X.*Y.*sin(pi*Y.*Z) % for example
Do I need to use permute
somewhere? I know that I could simply make a triple loop, but as we know that is slow.
Thanks!