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!