First, obtain the lines in a cell array using textread
:
C = textread(filename, '%s', 'delimiter', '\n')
Then you can use regexp
to split each line into chars:
result = cellfun(@(x)regexp(x, '\w+', 'match'), C, 'Uniform', false)
The result should be a cell array of cell arrays of chars:
result =
{'a' 'e' 'e' 'a' 'a' 'i'}
{'i' 'i' 'a' 'e' 'u' 'i' 'i' 'a'}
{'a' 'i' 'e' 'i' 'i' 'i' 'a' 'i'}
Alternatively, if you're handling only space-delimited letters (that is, one character only), you can store each line as a string (equivalent to an array of chars in C). To do that, just remove the spaces. For example, use regexprep
:
result = cellfun(@(x)regexprep(x, ' ', ''), C, 'Uniform', false)
result =
'aeeaai'
'iiaeuiia'
'aieiiiai'
For instance, to access the e
in the second line, you can write result{2}(4)
.