function display_digit(img,varargin) % FORMAT display_digit(img,[Lab,TruLab]) % Displays digits stored as column vectors in matrix img % % img - 256 x n matrix, where each column corresponds to a 16x16 image % Lab - Optional length n-vector of numbers, to be displayed above the % image of the digit. % TruLab- Optional length n-vector of numbers, true label; "Lab" is % then the predicted label. If Lab(i) ~= TruLab(i), a message is % shown below the image, indicating the true label. %________________________________________________________________________ % Script: display_digit.m % Purpose: Display gray scale digits with labels % Author: Tom Nichols % Date: 29 Jan 2012 % if nargin>1 Lab=varargin{1}; else Lab=[]; end if nargin>2 TruLab=varargin{2}; else TruLab=[]; end nImg=size(img,2); clf % Figure out dimensions of subplots if (nImg==1) N=1;J=1; else N=ceil(sqrt(nImg)*1.75); J=ceil(nImg/N); end % Loop over images for i=1:nImg subplot(J,N,i); imagesc(reshape(img(:,i),[16 16]),[0 150]); axis image set(gca,'box','off','Xtick',[],'Ytick',[]) if ~isempty(Lab) title(num2str(Lab(i)),'fontsize',18) end if ~isempty(TruLab) && TruLab(i)~=Lab(i) xlabel(sprintf('(%d)',TruLab(i)),'color',[1 0 0]) end end