teaLeef
teaLeef

Reputation: 1989

Creating an array from vectors in a specific order

I have three vectors of different lengths X,Y,Z

for each combination (X(i),Y(j),Z(k)), I have computed a value C(i,j,k) = f(X(i),Y(j),Z(k)) which is a float.

I have stored these results in a matrix M which has 1 column and length(X)*length(Y)*length(Z) columns so that the results correspond to the computation in the following order: (eg with 2 elements for each vector)

[f(X(1) Y(1) Z(1))
f(X(1) Y(1) Z(2))
f(X(1) Y(2) Z(1))
f(X(1) Y(2) Z(2))
f(X(2) Y(1) Z(1))
f(X(2) Y(1) Z(2))
f(X(2) Y(2) Z(1))
f(X(2) Y(2) Z(2)]

How can I write the values of f(X(i),Y(j),Z(k)) in a 3D array T so that T(i,j,k)=f(X(i),Y(j),Z(k))? A for loop doesn't work for me because of the number of elements.

Upvotes: 1

Views: 48

Answers (1)

wrongu
wrongu

Reputation: 580

Does the reshape function do what you want?

Upvotes: 2

Related Questions