Reading Text and Parsing by Character

2 vues (au cours des 30 derniers jours)
Nikolay Rodionov
Nikolay Rodionov le 30 Juil 2012
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 commentaires
Walter Roberson
Walter Roberson le 30 Juil 2012
[] 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 le 31 Juil 2012
Yes

Connectez-vous pour commenter.

Réponse acceptée

Albert Yam
Albert Yam le 30 Juil 2012
Modifié(e) : Albert Yam le 30 Juil 2012
rand.txt = 'thequickbrownfoxjumpsoverthelazydog';
finalarray = regexp(rand.txt,'[a-z]','match')
Edit: if every character, including periods and such
finalarray = regexp(rand.txt,'.','match')

Plus de réponses (1)

Walter Roberson
Walter Roberson le 30 Juil 2012
finalarray = num2cell(rand.txt);
  1 commentaire
Nikolay Rodionov
Nikolay Rodionov le 31 Juil 2012
this works great too

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by