Finding the particular pattern from cell array
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Gopalakrishnan venkatesan
 il 4 Ago 2017
  
    
    
    
    
    Modificato: Stephen23
      
      
 il 4 Ago 2017
            I have a cell array,
A = {'file.m', 'file.log', 'file_dsaf_dsfaf.log', 'data.log'}
I need to extract the element starting with fi and ending with log
How can i extract it using the regular expression?
Thanks a lot
0 Commenti
Risposta accettata
  Stephen23
      
      
 il 4 Ago 2017
        
      Modificato: Stephen23
      
      
 il 4 Ago 2017
  
      >> A = {'file.m', 'file.log', 'file_dsaf_dsfaf.log', 'data.log'};
>> idx = cellfun('isempty',regexp(A,'^fi.*log$'));
>> B = A(~idx)
B =
    'file.log'
    'file_dsaf_dsfaf.log'
Note that if you are using dir to get the file data then it would be much simpler and more efficient to filter the filenames using dir and the wildcard operator *:
S = dir('fi*.log');
B = {S.name}
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su File Operations in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!