matlab - loop through all files in a given folder in Unix
Posted by rolf on Wednesday, 25 February 2015
In matlab, if you want to process all files in folder and the files have rather different file names you can use following code snippet in Unix environments, like linux
%// use ls command to get a long string of all files you are interested in [status,cmdout] = unix('ls /path/to/directory/*filesMustContainThisWord*'); %// convert that long string to cells, %// using the end of line character as the splitting point %// note: in other operating systems \r or \f %// or a combination might be the EOL character cmdout_cells = regexp(cmdout, '\n', 'split'); % // loop through all file names, last cell is empty '' for i = 1 : length(cmdout_cells)-1 fprintf('%s \n', cmdout_cells{i}); %// just prints the file names end
blog_external_links:
Add new comment