Can anyone explain me what this line do strcmp(D(i).name,'..')?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Henrik
el 8 de Dic. de 2014
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 comentarios
Titus Edelhofer
el 8 de Dic. de 2014
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
el 8 de Dic. de 2014
So the imgcounter is actually just counting the number of files in the directory?
Vinay Kumar
el 8 de Dic. de 2014
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!