how to find the length of a directory

10 views (last 30 days)
I have a folder in which my images are saved.I want to find the no. of .tif files stored in the directory. I wrote j=length(dir(['E:\IMAGES\*.tif'])); It shows an error Index exceeds matrix dimensions Please can anyone explain this?
Folder Name : E:\IMAGES File name image_####.tif where #### is any four digit number
THANKS IN ADVANCE

Accepted Answer

Jos (10584)
Jos (10584) on 21 Dec 2013
The error is most likely to the fact there is variable called dir (or, less likely, length) in your workspace. Try this
which dir
which length
To reproduce the error:
clear dir
dir('*.*')
dir = 1:4 ;
dir('*.*')
which gives the error " ??? Index exceeds matrix dimensions. ". The reason is that the last line is looking for the 42nd element of the vector dir, which has only four elements. (the ascii code of '*' is 42).

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!