MATLAB: How to vectorize this code

MATLABvectorization

while b < (length(data))
ECG(i,:) = data(f:b);
f = f+477;
b=b+477;
i= i+1;
end

Best Answer

It appears that your code is segmenting your EKG record into 477-element segments.
The reshape (link) function could likely do this in one call. Assuming that ‘data’ is a row vector, try this:
EKG = reshape(data, [], 477);
The length of ‘data’ must be an integer multiple of 477, so check that first, and trim the length if necessary before the reshape call.