Reputation: 1989
x,y,z are three vectors.
If I run three for loops in matlab and stock at each iteration A(i,j,k) = [x(i) y(j) z(k)]
, then I will get an array.
What is the most efficient way of creating this array?
Upvotes: 0
Views: 45
Reputation: 26069
The notation you used in the question (A(i,j,k) = [x(i) y(j) z(k)]
) has a bug. It creates a 3D matrix A and tried to assign a value to it's (i,j,k) element, only you assign 3 values (x(i),y(j),z(k)).
So if I understand you correctly, what you meant is:
A = [x(:) , y(:), z(:)] ;
this will give and array of size 3xn. Unless you actually meant to have a 3d matrix, then look into ndgrid
\ meshgrid
options.
Upvotes: 1