MATLAB: How to process each line or word in a text file using MATLAB

image processingtext file

The contents of the text file are in this format, where each line consists of two names with a number attached with an underscore:
Abdel_Madi_Shabneh_0001 Dean_Barker_0001
Abdel_Madi_Shabneh_0001 Giancarlo_Fisichella_0001
Abdel_Madi_Shabneh_0001 Mikhail_Gorbachev_0001
Abdul_Rahman_0001 Portia_de_Rossi_0001
Abel_Pacheco_0001 Jong_Thae_Hwa_0002
Abel_Pacheco_0002 Jean-Francois_Lemounier_0001
and I'd like to reformat the content to make it like this, in other words but them into cell of nX2 dimension so I can each them easily:
'Abdel_Madi_Shabneh_0001' 'Dean_Barker_0001';
'Abdel_Madi_Shabneh_0001' 'Giancarlo_Fisichella_0001';
'Abdel_Madi_Shabneh_0001' 'Mikhail_Gorbachev_0001';
'Abdul_Rahman_0001' 'Portia_de_Rossi_0001';
'Abel_Pacheco_0001' 'Jong_Thae_Hwa_0002';
'Abel_Pacheco_0002' 'Jean-Francois_Lemounier_0001';
Is there a way how can I do it automatically? Thanks

Best Answer

Just use textscan:
fid = fopen('temp.txt','rt');
C = textscan(fid,'%s%s');
fclose(fid);
C = cat(2,C{:});
to get this:
>> C
C =
'Abdel_Madi_Shabneh_0001' 'Dean_Barker_0001'
'Abdel_Madi_Shabneh_0001' 'Giancarlo_Fisichella_0001'
'Abdel_Madi_Shabneh_0001' 'Mikhail_Gorbachev_0001'
'Abdul_Rahman_0001' 'Portia_de_Rossi_0001'
'Abel_Pacheco_0001' 'Jong_Thae_Hwa_0002'
'Abel_Pacheco_0002' 'Jean-Francois_Lemounier_0001'
The example text file is attached here: