Showing posts with label directory in matlab. Show all posts
Showing posts with label directory in matlab. Show all posts

Friday, June 29, 2012

How to read files available in a current directory and read their name in Matlab?

Imagine a directory contains some image files named ref1.png ref2.png ......and test1.png test2.png...........

We want to print the names of these files available in C:\Users\code

dir_loc='C:\Users\code';



ref_files=dir( strcat(dir_loc,'ref*.png'));
test_files=dir(strcat(dir_loc,'test*.png'));


for i=1:numel(ref_files)

    ref_files(i).name
    test_files(i).name

end


The above code will print all the files which name's contain either ref or test string from the "code" directory.