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.
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.
when dealing with file names and paths, it is usually better to use "fullfile", rather than "strcat".
ReplyDeleteYes. That's a good option as well.
ReplyDelete