jdl
jdl

Reputation: 6323

Parsing issue with textread in matlab

given:

v = textread(strPathFilename, '%s', 'delimiter', ' ', 'endofline', '\r\n');

I want returned 'v' as a cellArray of columns from the file.

but instead I get 1 column of everything parsed by a space.

Desired:

file:
1 2 3 4 CR
5 6 7 8 CR
9 10 11 12 CR

v{1}:
1, 5, 9

v{2}:
2, 6, 10

Upvotes: 0

Views: 70

Answers (2)

fpe
fpe

Reputation: 2750

How about this:

C = textscan(fid,'%f %f %f %f %s','Delimiter','\n');

I hope this helps.

Upvotes: 0

H.Muster
H.Muster

Reputation: 9317

You can use textscan to achieve this:

fid = fopen(strPathFilename,'r')
v = textscan(fid, '%d%d%d%d', 'delimiter', ' ', 'endofline', '\r\n')
fclose(fid)

This results in

v = 

    [3x1 int32]    [3x1 int32]    [3x1 int32]    [3x1 int32]

with each of the cells containing one column.

Upvotes: 1

Related Questions