The reshape routine has the following syntax
y = reshape(x,dims)
where dims
is either a vector containing the dimensions of the
output, or is a sequence of scalars. In particular, you can
use the form
y = reshape(x,dim1,dim2,...,dimn)
or
y = reshape(x,[dim1,dim2,...,dimn])
Note that for a reshape
to be legal, the output array
must have the same number of elements in it as the input array.
Here is an example of a multidimensional array being reshaped into a matrix
--> x = rand(2,2,2) x = <double> - size: [2 2 2] (:,:,1) = Columns 1 to 2 0.814723686393179 0.126986816293506 0.905791937075619 0.913375856139019 (:,:,2) = Columns 1 to 2 0.632359246225410 0.278498218867048 0.0975404049994095 0.546881519204984 --> y = reshape(x,4,2) y = <double> - size: [4 2] Columns 1 to 2 0.814723686393179 0.632359246225410 0.905791937075619 0.0975404049994095 0.126986816293506 0.278498218867048 0.913375856139019 0.546881519204984 --> y = reshape(x,[4,2]) y = <double> - size: [4 2] Columns 1 to 2 0.814723686393179 0.632359246225410 0.905791937075619 0.0975404049994095 0.126986816293506 0.278498218867048 0.913375856139019 0.546881519204984