0% found this document useful (0 votes)
124 views2 pages

Cs 1173 Reshape Function

The MATLAB reshape function returns a new array with the same elements as the original array, but with a different number of rows and columns. The number of rows times the number of columns in the reshaped array must equal the total number of elements in the original array. Examples demonstrate reshaping a 2D array into different dimensional arrays by specifying the number of rows and columns for the reshaped array.

Uploaded by

SeeTohKevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views2 pages

Cs 1173 Reshape Function

The MATLAB reshape function returns a new array with the same elements as the original array, but with a different number of rows and columns. The number of rows times the number of columns in the reshaped array must equal the total number of elements in the original array. Examples demonstrate reshaping a 2D array into different dimensional arrays by specifying the number of rows and columns for the reshaped array.

Uploaded by

SeeTohKevin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS 1173: MATLAB 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

You might also like