No looping needed...as long as the numeric values are regular (ie, same number of columns each record) as shown.
>> c=textread('alex.dat','%s','delimiter','\n','whitespace','')
c =
'1 1 -1 1 1 -1'
'1 -1 1 1 -1 1'
''
'sdasr'
'-1 1 1 1 -1 -1 '
>> A=str2num(char(c(~cellfun(@(x) all(isletter(x)),c))))
A =
1 1 -1 1 1 -1
1 -1 1 1 -1 1
-1 1 1 1 -1 -1
>>
ADDENDUM
Above will fail if the string happens to have any digits in it; more robust would be two steps; first remove blank lines and then use any instead of all for the alpha test.
isstrprop might turn out useful here, too...
ADDENDUM 2 :)
IF were going to use a loop and fgetl here, I'd do it more like--
A=[];
while ~feof(fid)
try
A=[A;str2num(fgetl(fid))];
catch
end
end
Best Answer