Reading Text and Parsing by Character

조회 수: 3 (최근 30일)
Nikolay Rodionov
Nikolay Rodionov 2012년 7월 30일
Hi, I need to somehow read in a text file with no standard delimiters (spaces,tabs,ect.) and parse it by character into a long single row array.
For example,
rand.txt = "thequickbrownfoxjumpsoverthelazydog"
finalarray = ['t' 'h' 'e' 'q' 'u' 'i' 'c' 'k'....]
Any advice??
Thanks in advance!
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 7월 30일
[] is the horizontal concatenation operator. ['a' 'b'] has exactly the same result as 'ab' . Are you looking for a cell array of strings? {'a' 'b'} ?
Nikolay Rodionov
Nikolay Rodionov 2012년 7월 31일
Yes

댓글을 달려면 로그인하십시오.

채택된 답변

Albert Yam
Albert Yam 2012년 7월 30일
편집: Albert Yam 2012년 7월 30일
rand.txt = 'thequickbrownfoxjumpsoverthelazydog';
finalarray = regexp(rand.txt,'[a-z]','match')
Edit: if every character, including periods and such
finalarray = regexp(rand.txt,'.','match')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 30일
finalarray = num2cell(rand.txt);

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by