MATLAB: Showing multiple images in one window in Matlab

image processingMATLABsubplot

Why doesn't the following code show the images?
clear all;
image_name = 'woman.png';
I = gray_imread(image_name);
N = 12;
J = zeros(size(I,1), size(I,2), N);
for i=1:N
J(:,:,i) = I;
end
sqrtt = ceil(sqrt(N));
m = sqrtt;
n = sqrtt;
for k=1:N
K = J(:,:,k);
subplot(m,n,k);
imshow(K);
set(gca,'xtick',[],'ytick',[])
end
How can I solve the issue?

Best Answer

Change
J = zeros(size(I,1), size(I,2), N);
to
J = zeros(size(I,1), size(I,2), N, class(I));