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

4 ビュー (過去 30 日間)
Sayak
Sayak 2013 年 3 月 31 日
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?

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 31 日
fullfile(mydir, allfiles(ctr).name)
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 1 日
In your fopen() statement, change the 'w' to 'wt'
Sayak
Sayak 2013 年 4 月 3 日
Ok, done. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by