Step 2:  

Randomly select 20 of the 5000 images and plot them to a figure window just to see what they look like.

clear all;
close all;
clc;


[XTrain,YTrain] = digitTrain4DArrayData;
size(XTrain)      %images
size(YTrain)      %correct answer labels


%The following lines are just used to show a few random examples of the written images just so you can see what they look like
perm = randperm(size(XTrain,4),20);  % Randomize the order of images in XTrain
for i = 1:20
subplot(4,5,i);
imshow(XTrain(:,:,:,perm(i)));
end
 
At this stage, save and run the program to see what it looks like.  You can save it under any name you'd like, for example CNNdigits.