From: Sean on 5 Apr 2010 11:48 "Ana-Maria Cuculescu" <amcuculescu(a)gmail.com> wrote in message <hpcvrg$6ms$1(a)fred.mathworks.com>... > Hi Sean, > > It doesn't work: > > my_dir = ls; > found = strfind(my_dir,'jpg'); > > ??? Error using ==> strfind > Input strings must have one row. > > although I have a file named jpg.jpg in the directory... > > Thanks in advance. It works on my machine. I also can't reproduce that error. What is my_dir equal to after running ls? To adjust for jpg.jpg you could either subtract 1 from the total or use '.jpg' as your pattern.
From: Ana-Maria Cuculescu on 5 Apr 2010 11:53 This works. Thanks. It is what I wanted. "Steven Lord" <slord(a)mathworks.com> wrote in message <hpcvvd$8jf$1(a)fred.mathworks.com>... > > "Ana-Maria Cuculescu" <amcuculescu(a)gmail.com> wrote in message > news:hpcvrg$6ms$1(a)fred.mathworks.com... > > Hi Sean, > > > > It doesn't work: > > > > my_dir = ls; > > found = strfind(my_dir,'jpg'); > > > > ??? Error using ==> strfind > > Input strings must have one row. > > > > although I have a file named jpg.jpg in the directory... > > > > Thanks in advance. > > > > For each of the image file extensions you want to count, use DIR. > > D = dir('*.jpg'); > numberOfJpg = numel(D); > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ >
From: Walter Roberson on 6 Apr 2010 18:55 Ana-Maria Cuculescu wrote: > How can I count the image files in active directory ? > For instance, if I have 9 images in the active directory, I want to > write a code that counts the number of images in my directory and > returns this number: 9. The code you have been given so far, and which you said worked for your needs, does not in fact solve the problem you asked us to solve. The code that solves the problem you asked us to solve would use dir() specifiying the appropriate directory (_just_ the directory), store the result into a variable, and then use the isdir field of the returned structure to eliminate any subdirectories (or the current directory.) EVERY file (that is not a directory or device file or FIFO queue or similar special file) that appears in your directory is an image file. The program for which it is an image file might not have been written yet... might never get written. I repeat, EVERY file is an image file. EVERY file is also a music file. EVERY file is also the compressed version of a world-revolutionizing scientific theory. You may _think_ that the file just says "The brown cattail waved over the hazy frog.", but that's a matter of interpretation, a lack of experience or imagination. Every file can be interpreted in any way you can imagine. Now, possibly you wish to restrict your program to only finding image files that your version of Matlab knows how to deal with. If so, then iminfo() might be of service to you -- but running the directory information by file extension isn't going to be sufficient. I have run into my share of TIFF- or GIF- named files that were actually JPEG files internally. You don't know until you have tested the file whether it is one of the known file formats are not. Suffixes are just conventions.
First
|
Prev
|
Pages: 1 2 Prev: how to randomly select pixels from an image Next: renaming financial time series objects |