Can anyone explain me what this line do strcmp(D(i).name,'..')?
古いコメントを表示
I am trying to read the number of images in a folder the following code. Can anyone explain this?
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1; % Number of all images in the training database
end
採用された回答
その他の回答 (1 件)
Henrik
2014 年 12 月 8 日
strcmp(D(i).name,'.'
this compares the string in D(i).name to '.'. If the string is indeed '.', it returns TRUE (in MATLAB, this is the same as 1).
Similarly for the two other strcmp: if the string is equal to '..' or 'Thumbs.db' it returns true.
The | between the three checks means either. So
strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db')
is true if the string in D(i).name is either '.', '..' or 'Thumbs.db'.
The not in front of all this means that imcount will increase by 1 if the string in D(i).name is neither '.', '..' nor 'Thumbs.db'
3 件のコメント
Titus Edelhofer
2014 年 12 月 8 日
In summary: it looks as if someone calls "dir" and loops over the result to count all files that are not "." (current folder), ".." which is the parent folder or "Thumbs.db" which is a file created by Windows explorer ...
Titus
Henrik
2014 年 12 月 8 日
So the imgcounter is actually just counting the number of files in the directory?
Vinay Kumar
2014 年 12 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!