Reading Text and Parsing by Character

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 件のコメント

Oleg Komarov
Oleg Komarov 2012 年 7 月 30 日
The example you provided is misleading (or I don't understand it) since the second line of code will return exactly the first line.
Nikolay Rodionov
Nikolay Rodionov 2012 年 7 月 30 日
Sorry I was in a rush, what I meant was that I will have a text file that contains a line like "thequickbrownfoxjumpsoverthelazydog"
I want to create a string array that looks like ['t' 'h' 'e' 'q' 'u' 'i' 'c' 'k'....] where the input string is parsed by each character.
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 日

1 投票

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 日

1 投票

finalarray = num2cell(rand.txt);

1 件のコメント

Nikolay Rodionov
Nikolay Rodionov 2012 年 7 月 31 日
this works great too

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by