Reading Text and Parsing by Character

6 次查看(过去 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'} ?

请先登录,再进行评论。

采纳的回答

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 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by