How to read and process line by line in matlab?
조회 수: 7 (최근 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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!