23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1 Data Structures<br />

A = [1:8; 11:18; 21:28; 31:38; 41:48]<br />

A =<br />

1 2 3 4 5 6 7 8<br />

11 12 13 14 15 16 17 18<br />

21 22 23 24 25 26 27 28<br />

31 32 33 34 35 36 37 38<br />

41 42 43 44 45 46 47 48<br />

B = circshift(A, [0, 3])<br />

B =<br />

6 7 8 1 2 3 4 5<br />

16 17 18 11 12 13 14 15<br />

26 27 28 21 22 23 24 25<br />

36 37 38 31 32 33 34 35<br />

46 47 48 41 42 43 44 45<br />

Now take A and shift it along both dimensions: three columns to the right<br />

and two rows up:<br />

A = [1:8; 11:18; 21:28; 31:38; 41:48];<br />

B = circshift(A, [-2, 3])<br />

B =<br />

26 27 28 21 22 23 24 25<br />

36 37 38 31 32 33 34 35<br />

46 47 48 41 42 43 44 45<br />

6 7 8 1 2 3 4 5<br />

16 17 18 11 12 13 14 15<br />

Since circshift circulates shifted rows and columns around to the other end<br />

of a matrix, shifting by the exact size of A returns all rows and columns to<br />

their original location:<br />

B = circshift(A, size(A));<br />

all(B(:) == A(:)) % Do all elements of B equal A?<br />

ans =<br />

1 % Yes<br />

1-38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!