MATLAB: How to read and work with all the files from a directory

edge detectionfile read

I have a directory full of image-files. I want to read all the files and then calculate the number of white pixel present for each of the files then write to to another file. To achieve this I used following code but in vein.
mydir = 'E:\matlab\dog\';
allentries = dir(mydir);
diridxs = [allentries.isdir];
alldirs = allentries(diridxs);
allfiles = allentries(~diridxs);
for ctr = 1:length(allfiles)
disp(nnz(edge(rgb2gray(imread(allfiles(ctr).name)))));
end
After using this code matlab is showing some error [File "247000.jpg" does not exist]. Though that file exists in that path. How to get rid of that problem?

Best Answer

fullfile(mydir, allfiles(ctr).name)