How to read and process line by line in matlab?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
rupak katwal
el 28 de Sept. de 2019
I have the text file, where it is contain list of the combination of letter,number and special character. Here character will be the number until first space in the string, and after space it consits of all the character LIKE AN EXAMPLE BELOW
11455 01adsd@#$
1223 AaFg3434
1345 01ADAS FE
14090 01aFAF
1585 !%^r^&&*^
1644 01!ggjGIJiu
178 !Aa8Y348Y23RHF
Here i want to first read number until a space and after that i want to read through each character.
0 comentarios
Respuesta aceptada
Adam Danz
el 28 de Sept. de 2019
Editada: Adam Danz
el 28 de Sept. de 2019
I pasted your example into the attached text file. This reads that file and then parses the number and char array components.
% Read in the text file
ca = strtrim(strsplit(fileread('myTextFile.txt'),'\n'))';
% parse the leading numbers and then the rest after the first space
nums = str2double(regexp(ca,'^\d+ ','match','once'));
chars = cellfun(@(c,x)c(x+1:end),ca,regexp(ca,'^\d+ ','end'),'UniformOutput',false);
Result
nums =
11455
1223
1345
14090
1585
1644
178
chars =
7×1 cell array
{'01adsd@#$' }
{'AaFg3434' }
{'01ADAS FE' }
{'01aFAF' }
{'!%^r^&&*^' }
{'01!ggjGIJiu' }
{'!Aa8Y348Y23RHF'}
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!