How to transpose N-dimensional array using octave/Matlab

If you have an array with size of m x n x p and would like to transpose the matrix, octave will give you error. Basically transpose is not defined for N-dimensional array. But for example you want to transpose from shape (m,n,p) to (n,m,p), you can do this with the command “permute”.

for example, if we create a 3D array,
X=rand(7,8,9);

and would like to transpose to 8,7,9 shape, simply type
Y=permute(X,[2 1 3]));

you can check by typing size(Y). 🙂

Advertisements

One Response

  1. Thanks, this was useful 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: