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

1 view (last 30 days)
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?

Accepted Answer

Walter Roberson
Walter Roberson on 31 Mar 2013
fullfile(mydir, allfiles(ctr).name)
  3 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!