I'm having some trouble implementing the following MATLAB code in python.
for i = 1:N
if (feof(fid) ~= 1)
for j = 1:K
if (feof(fid) ~= 1)
tmp = fread(fid, 1, 'float');
data.(fldnames{j,1}).Samples(i) = tmp;
else
disp('Error: End of file reached');
end
end
else
disp('Error: End of file reached');
end
This is my 'like-for-like' python attempt,
sampleList = numpy.zeros((N, K))
for i in range(1, N) :
for j in range(1, K) :
if EOF == 0 :
try :
samples = array.array("f")
samples.fromfile(f, 1)
sampleList[i, j] = samples[0]
except :
EOF = 1
return sampleList
But I'm having trouble catching both of the EOFs. Is there an easier, more pythonic way of writing this code?