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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 31 Mar 2013
fullfile(mydir, allfiles(ctr).name)
  3 Commenti
Walter Roberson
Walter Roberson il 1 Apr 2013
In your fopen() statement, change the 'w' to 'wt'

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by