How to get common sub string in cell array string?
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Example:
cell_arr =
  3×1 cell array
    {'A.A1.A11.A111'                         }
    {'A.A1.A12.A121'                         }
    {'Event_State.Chart.A.A1.A12'}
How to get output = A.A1 ?
0 Commenti
Risposta accettata
  Stephen23
      
      
 il 17 Mar 2020
        
      Modificato: Stephen23
      
      
 il 17 Mar 2020
  
      1- Download and unzip John D'Errico's FEX submission
2- Modify commonsubstring by replacing every 
regexp(..., cellsubstr)
with
regexp(..., regexptranslate('escape',cellsubstr))
3- Call commonsubstrings in a loop, e.g.:
C = {'A.A1.A11.A111','A.A1.A12.A121','Event_State.Chart.A.A1.A12'};
S = C{1};
for k = 2:numel(C)
    S = commonsubstring(S,C{k});
end
This returns the longest common substring (your output example is not the longest common substring):
>> S
S = A.A1.A1
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!


