%-------------------------------------% % Lab9 p.4 % % Date: 11/5/02 % % % % Gun Srijuntongsiri % % gs61 % % ?????? % %-------------------------------------% % Variables % --------- % A = the array to be reversed, assume previously defined. % Swap the first half of the array with the second half for i=1:floor(size(A,1)/2) for j=1:size(A,2) tmp=A(i,j); A(i,j)=A(size(A,1)-i+1,size(A,2)-j+1); A(size(A,1)-i+1,size(A,2)-j+1)=tmp; end end % If odd number of rows, have to take special care of the center row if mod(size(A,1),2)==1 i = ceil(size(A,1)/2); for j=1:floor(size(A,2)/2) % only to half, why? % Otherwise, you swap them twice, and % back to the initial stage tmp=A(i,j); A(i,j)=A(size(A,1)-i+1,size(A,2)-j+1); A(size(A,1)-i+1,size(A,2)-j+1)=tmp; end end % Output the result A