How to read and process line by line in matlab?

6 次查看(过去 30 天)
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.

采纳的回答

Adam Danz
Adam Danz 2019-9-28
编辑:Adam Danz 2019-9-28
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 个)

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by