Clear Filters
Clear Filters

I generated 3 (1X1) random numbers using a=rand(1,1,3). When I gave [b n] =shiftdim(a), I got a b matrix of 3X1 matrix using the elements of variable a and got the n value as 2. Can u explain the concept behind this and how the value of “n” is det

1 view (last 30 days)
I generated 3 (1X1) random numbers using a=rand(1,1,3). When I gave [b n] =shiftdim(a), I got a b matrix of 3X1 matrix using the elements of variable a and got the n value as 2. Can u explain the concept behind this and how the value of “n” is determined?

Answers (1)

Jan
Jan on 5 Jul 2013
Edited: Jan on 5 Jul 2013
This is explained exhaustively in the documentation, so please read:
help shiftdim
doc shiftdim
Another good idea is to look into the source code:
edit shiftdim
You'll find out, that n replied by shiftdim is the number of dimensional shifts, which is required to bring the first non-signelton dimension (the first one which has not the length 1) to the front. In your case, 2 means, that the 3rd dimension is shifted twice to get the 1st one.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!