MATLAB: How can you extract odd and even rows and columns from image to seperate image outputs

imagesodd and even rows

Hi there. I might be overthinking this. I often do but I'm trying to take the odd columns and rows and then even rows and columns from an image and then output them to form two seperate images in a subplot, with the original image maintained. I am confused at how I handle the additional dimension and I think this might be causing the output to fail. Any advice would be much appreciated. Code below.
%Load image
function [RowsEven, ColsEven]=oddevenpic(A);
A=imread('brain.jpg');
sizeofarray=size(A);
B=zeros(sizeofarray(1), sizeofarray(2));
C=zeros(sizeofarray(1), sizeofarray(2));
image(B);
image(C);
for r=1:sizeofarray(1);
for c=1:sizeofarray(2);
for RowsEven=mod(A,r)==0;
for ColsEven=mod(A,c)==0;
if (A(r)==RowsEven) | (A(c)==ColsEven);
(B(r)==RowsEven) & (B(c)==ColsEven);
else
(C(r)==(A(r)~=RowsEven)) & (C(c)==(A(c)~=ColsEven));
end
end
end
end
end
% %Display
subplot(3,2,3);
imshow(A);
title('Original Image')
%

subplot(3,2,2);
imshow(B);
title('Even Pixels Only')
%
subplot(3,2,1);
imshow(C)
title('Odd Pixels Only')
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);

Best Answer

B=A(2:2:size(A,1),2:2:size(A,2),:);%Even Pixels Only
C=A(1:2:size(A,1),1:2:size(A,2),:);%Odd Pixels Only