Upload
seetohkevin
View
216
Download
2
Embed Size (px)
DESCRIPTION
Reshape Matlab
Citation preview
B=reshape(A,n,m)
CS 1173: MATLAB reshape functionThereshapefunctionreturnsanewarraywithnrowsandmcolumns(n*mmustequalthenumberofelementsintheoriginalarray).Thenewarrayhasthesameelementsastheoriginal.
reshapedarray
arraytoreshape
#ofcolumnsinresult
#ofrowsinresult
Reshapingstrategy:findthelinearrepresentationandrecutbasedonthenumberofrowsinthereshapedarray.
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)
recut
B=
C=reshape(A,2,3)
recut
C=
Example2:TwomorewaystoreshapetoarrayA
A = [1, 2, 3; 4, 5, 6]; B = reshape(A, 6, 1);C = reshape(A, 1, 6); A= A(:)=
B=reshape(A,6,1)
recut
B=
C=reshape(A,1,6)
recut
C=
Example3:Reshapingarowvector
A = [1, 2, 3, 4, 5, 6]; B = reshape(A, 2, 3);C = reshape(A, 3, 2);
A=
recut
B=reshape(A,2,3)
B=
recut
C=reshape(A,3,2)
C=
Slide Number 1Slide Number 2