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

2 vues (au cours des 30 derniers jours)
Sayak
Sayak le 31 Mar 2013
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 31 Mar 2013
fullfile(mydir, allfiles(ctr).name)
  3 commentaires
Walter Roberson
Walter Roberson le 1 Avr 2013
In your fopen() statement, change the 'w' to 'wt'
Sayak
Sayak le 3 Avr 2013
Ok, done. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by