Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
permute

Subject: permute

From: Zain

Date: 16 Aug, 2010 08:42:05

Message: 1 of 6

Hello,

    I am finding it difficult to understand how the "permute" command works.

For example, if I have a matrix, A = [1 2 3 0;0 3 4 1;1 2 3 4]

When i use the command, permute(A,[2 3 1]), the answer I obtain is,

ans(:,:,1) =

     1
     2
     3
     0

ans(:,:,2) =

     0
     3
     4
     1

ans(:,:,3) =

     1
     2
     3
     4

What I don't understand is, which part of the 'order' that I specified ([2 3 1]) helps in obtaining the above output. Roughly, what does the '2' , '3' and '1' indicate ? .

Hope someone can help me understand this simple function. Thank you.

Zain

Subject: permute

From: Bruno Luong

Date: 16 Aug, 2010 09:55:08

Message: 2 of 6

"Zain " <nonamenoface@rediffmail.com> wrote in message <i4atks$dsi$1@fred.mathworks.com>...
> Hello,
>
> I am finding it difficult to understand how the "permute" command works.
>
> For example, if I have a matrix, A = [1 2 3 0;0 3 4 1;1 2 3 4]
>
> When i use the command, permute(A,[2 3 1]), the answer I obtain is,
>

It permute the *dimensions* of the array. After calling

B = permute(A,[2 3 1])

Then

A(i,j,k) is equal to B(j,k,i) for all valid triplets (i, j, k).

Look at the order of (i,j,k) and (j,k,i): the later triplet is the organized as #2,3,1 of the first.

Bruno

Subject: permute

From: ImageAnalyst

Date: 16 Aug, 2010 12:10:33

Message: 3 of 6

Zain:
Do you know that you have a 2D matrix but that you are permuting in
3D? Perhaps that is what is confusing you. Try asking it to permute
the same number of dimensions as the array has and see if that makes
more sense to you.

Subject: permute

From: Zain

Date: 16 Aug, 2010 14:30:38

Message: 4 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a388b14a-1f6d-4145-809a-387b32d68db7@l20g2000yqm.googlegroups.com>...
> Zain:
> Do you know that you have a 2D matrix but that you are permuting in
> 3D? Perhaps that is what is confusing you. Try asking it to permute
> the same number of dimensions as the array has and see if that makes
> more sense to you.

 Yes Imageanalyst, I do realize that i have a matrix of 2 dimension matrix of size 4x3x1.
so naturally if I did a permute of the type , permute(A, [2 1]). it invokes the transpose and so on. I understood that fine. but since this matrix still has a value of 1 in the 3D sense, I figured i'll try out the command, permute(A,[2 3 1]) just to see what I would get. I expected MATLAB to produce an error if I tried something 'offlimits or invalid'. But instead it gave me an output, so i tried to figure that out and thats when it got confusing. so is the output a 'correct output' for the command, permute(A,[2 3 1]). if so, could you please show me a little more in detail how it is so ? . Thank you.

Subject: permute

From: Sean

Date: 16 Aug, 2010 14:47:26

Message: 5 of 6

"Zain " <nonamenoface@rediffmail.com> wrote in message <i4bi2e$ncd$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a388b14a-1f6d-4145-809a-387b32d68db7@l20g2000yqm.googlegroups.com>...
> > Zain:
> > Do you know that you have a 2D matrix but that you are permuting in
> > 3D? Perhaps that is what is confusing you. Try asking it to permute
> > the same number of dimensions as the array has and see if that makes
> > more sense to you.
>
> Yes Imageanalyst, I do realize that i have a matrix of 2 dimension matrix of size 4x3x1.
> so naturally if I did a permute of the type , permute(A, [2 1]). it invokes the transpose and so on. I understood that fine. but since this matrix still has a value of 1 in the 3D sense, I figured i'll try out the command, permute(A,[2 3 1]) just to see what I would get. I expected MATLAB to produce an error if I tried something 'offlimits or invalid'. But instead it gave me an output, so i tried to figure that out and thats when it got confusing. so is the output a 'correct output' for the command, permute(A,[2 3 1]). if so, could you please show me a little more in detail how it is so ? . Thank you.


Yes it is. Your matrix was originally size 3x4x1
Those sizes corresponding to rows, columns and pages resectively.

It permuted it so that is is to that that the second dimension, cols, is now in the rows place. So there should be 4 rows in the output. You put the third dimension, pages, size 1, in the columns place so that is why your result is showing 1 column. You put the rows, dimension 1 size 3, in the pages place so it should be 3 pages deep. It is, this behavior is expected!

-Sean

Subject: permute

From: Zain

Date: 16 Aug, 2010 16:18:08

Message: 6 of 6

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i4bj1u$rna$1@fred.mathworks.com>...
> "Zain " <nonamenoface@rediffmail.com> wrote in message <i4bi2e$ncd$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a388b14a-1f6d-4145-809a-387b32d68db7@l20g2000yqm.googlegroups.com>...
> > > Zain:
> > > Do you know that you have a 2D matrix but that you are permuting in
> > > 3D? Perhaps that is what is confusing you. Try asking it to permute
> > > the same number of dimensions as the array has and see if that makes
> > > more sense to you.
> >
> > Yes Imageanalyst, I do realize that i have a matrix of 2 dimension matrix of size 4x3x1.
> > so naturally if I did a permute of the type , permute(A, [2 1]). it invokes the transpose and so on. I understood that fine. but since this matrix still has a value of 1 in the 3D sense, I figured i'll try out the command, permute(A,[2 3 1]) just to see what I would get. I expected MATLAB to produce an error if I tried something 'offlimits or invalid'. But instead it gave me an output, so i tried to figure that out and thats when it got confusing. so is the output a 'correct output' for the command, permute(A,[2 3 1]). if so, could you please show me a little more in detail how it is so ? . Thank you.
>
>
> Yes it is. Your matrix was originally size 3x4x1
> Those sizes corresponding to rows, columns and pages resectively.
>
> It permuted it so that is is to that that the second dimension, cols, is now in the rows place. So there should be 4 rows in the output. You put the third dimension, pages, size 1, in the columns place so that is why your result is showing 1 column. You put the rows, dimension 1 size 3, in the pages place so it should be 3 pages deep. It is, this behavior is expected!
>
> -Sean

Thanks sean. that helps. God knows why, I was thinking in terms of the actual rows and columns size rather than the dimensions. Anyway, that helped. adios.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us