Cs 1173 Reshape Function
Cs 1173 Reshape Function
Thereshapefunctionreturnsanewarraywithnrowsandm
columns(n*mmustequalthenumberofelementsintheoriginal
array).Thenewarrayhasthesameelementsastheoriginal.
B=reshape(A,n,m)
reshaped
array
arrayto
reshape
#of
#of
rowsin columns
result
inresult
Reshapingstrategy:findthelinearrepresentationandre
cutbasedonthenumberofrowsinthereshapedarray.
Example1:DifferentwaystoapplyreshapetoarrayA
A = [1, 2, 3; 4, 5, 6];
B = reshape(A, 3, 2);
C = reshape(A, 2, 3);
A=
A(:)=
B=reshape(A,3,2)
C=reshape(A,2,3)
B=
C=
recut
recut
Example2:TwomorewaystoreshapetoarrayA
A = [1, 2, 3; 4, 5, 6];
B = reshape(A, 6, 1);
C = reshape(A, 1, 6);
B=reshape(A,6,1)
A=
A(:)=
C=reshape(A,1,6)
C=
B=
recut
recut
Example3:Reshapingarowvector
A = [1, 2, 3, 4, 5, 6];
B = reshape(A, 2, 3);
C = reshape(A, 3, 2);
A=
B=reshape(A,2,3)
C=reshape(A,3,2)
B=
C=
recut
recut