Tuesday 15 July 2014

matlab - Applying functions to differently formatted files within a folder -


I have a folder full of files, column columns on the left side of each file. Some files have yyyymmdd dates, and others have mm / dd / yyyy dates in I minutebars1 () to yyyymmdd To type, and type minutebars2 () to mm / dd / yyyy I tried to do this with a statement, trying to say it, That if successfully read any course with a format within the loop running through all the files, then apply the correct function, though post below A code is not working, I get an error textscan lines Buddha as created went format string . How should this be done correctly?

 % reads all file names fPath = uigetdir ('.', 'Select the directory containing the CSV files'); If fPath == 0, error ('no folder selected'), end fNames = dir (fullfile (fPath, '*. Csv')); FNames = strcat (fPath, filesep, {fNames.name}); Process of each file for% I = 1: Length (fNames) fid = fopen (fNames {i}, 'rt'); If textscan (fid, '% i,% d:% d:% * d.% * D,% f,% d,% * c') for 1 minute pot 1 (fNames {i})% minutebars1 ( ); In the end if textscan (% fid, '% d /% d /% d,% d:% d:% d,% f,% d,% * c') for% 2 minutes bars2t (fNames {i}) Minbars2 (); End fclose (fid); Read the first line as a string and check that it is in the format << code>   

Code> fgetl and for reading a line, and for the regexp pattern test. Get the first line of the file% fid = fopen (fnames {i}, 'RT'); Str = fgetl (fid); Fclose (fid); Test for pattern mm / dd / yyyy (if regexp (str, '\ d \ d \ \ d \ d \ \ d \ d \ d \ d') minbars2 (fNames {i}); And minute 1 (FN name {i}); End

No comments:

Post a Comment