%% Assumes you're in a directory containing the .pgm files. %% Saves the images in a uint8 array called 'data'. filenames = dir('*.pgm'); filenames = sort({filenames.name}); % read the first to see how large it should be im = imread(filenames{1}); data = repmat(uint8(0),[size(im,1) size(im,2) length(filenames)]); for ii = 1:length(filenames) data(:,:,ii) = imread(filenames{ii}); end