replacing string variables with others
    2 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Dear all,
I have an excel file which I import into matlab.
This file is of size 400000 by 29 
   Among other columns I have a column that contains text information
   For instance here is some of the text information 
   textinfo={
    'A'
    'DRG MARS'
    'FO'
    'HYRETS > 250'
    'HYPERET > 250SQ'
    'LARGROIES 25-3'
    'LARG SURMATS 1-29'
    'SALL GRIES UP TO 25Q'
    'SUEMATS 40-9S'};
I want to find a code that will do the following mapping automatically
Replace 'A' by 'SE1' (for example)
Replace 'DRG MARS' by 'SE5'
Replace 'FO' by 'SE04' and so on
So as to create another column that will contain the 'SE1' 'SE04' etc corresponding to the text information according to the previous mapping mechanism
This matrix is large and doing this manually would be impossible
thanks a lot
0 Commenti
Risposta accettata
  Azzi Abdelmalek
      
      
 il 1 Feb 2013
        
      Modificato: Azzi Abdelmalek
      
      
 il 1 Feb 2013
  
      s1={'A','DRG MARS','FO'};
s2={'SE1','SE5','SE04'};
for k=1:numel(s1) 
 textinfo=cellfun(@(x) regexprep(x,s1{k},s2{k}),textinfo,'un',0);
end
textinfo
0 Commenti
Più risposte (2)
  Thorsten
      
      
 il 1 Feb 2013
        newtextinfo = textinfo;
idx =find(strcmp(textinfo, 'A'));
for i=1:numel(idx)
  newtextinfo{i} = 'SE1';
end
0 Commenti
  Jos (10584)
      
      
 il 1 Feb 2013
        Short and simple: STRREP
a = {'A','b','A','t'} ;
strrep(a,'A','xxx')
%  ans =  'xxx'    'b'    'xxx'    't'
0 Commenti
Vedere anche
Categorie
				Scopri di più su Characters and Strings 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!



