Read csv files by regulare expression function
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Damith
      
 am 7 Mai 2015
  
    
    
    
    
    Kommentiert: Damith
      
 am 8 Mai 2015
            Hi,
I have multiple .csv files in the following format from:
TRMM_1998_01_newntcl.csv
TRMM_1998_02_newntcl.csv
.
.
.
TRMM_1998_12_newntcl.csv
TRMM_1999_01_newntcl.csv
.
.
.
TRMM_1999_12_newntcl.csv
I have the following code and I need to modify to read by month (1-12). I appreciate if someone can help me to figure this out and modify the following code.
Thanks in advance.
      sad = dir('TRMM_*_newntcl.csv');
      cac = regexp( {sad.name}, '1998_[01]\d_[0-3]\_' ); 
      ism = not( cellfun( @isempty, cac ) );
      d   = sad(ism);
      ymdh=cell2mat(textscan([d.name], ...
              'TRMM_%4d_%2d_%2d%2d_newntcl.csv', ...
              'collectoutput',true));
0 Kommentare
Akzeptierte Antwort
  Walter Roberson
      
      
 am 7 Mai 2015
        month_to_match = 8;  %for example
str_for_month = sprintf('%02d', month_to_match);
regexp_for_month = [ '^TRMM_[12]\d{3}_[01]\d_' str_for_month '_'];
cac = regexp( {sad.name}, regexp_for_month );
3 Kommentare
  Walter Roberson
      
      
 am 8 Mai 2015
				regexp_for_month = [ '^TRMM_[12]\d{3}_' str_for_month '_'];
Siehe auch
Kategorien
				Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!