
% Firstly, please repeat lab1 to load the MNIST dataset to Matlab. Then
% use the following code to obtain a subset of MNIST:
%                tr_label= tr_label(1:1000,1);
%                tr_feats= tr_feats(1:1000,:);
% Alternatively, you can directly download this subset from :

load 'MNIST_subset.mat';

% you can now count how many samples are contained in the training set for
% each digit
for i=0:9
    num_of_sample(i+1)=size(find(tr_label==i),1);   % note here that the index for an array in Matlab starts from 1, which is different from C (or java)
end
% you can display the content for a variable by simply typing its name:
num_of_sample
% alternatively, you can double click that variable in the workspace

%% If you want to display all the samples for a specific digit (take '2' for example), the
% following command might help:
index=find(tr_label==2);
for i=1:length(index)
    subplot(11,11,i);
    im=reshape(tr_feats(index(i),:),28,28);
    imshow(uint8(im'));
end

%% Normalization
for i=1:size(tr_feats,1)
    tr_feats(i,:)=tr_feats(i,:)/sqrt(sum(tr_feats(i,:).^2));
end

