使用 min 函数指定访问的最终位置,本质上是增加一个条件判断:
done = false;
batch_size = 10000;
idx = 1;
while ~done
idx_end = min(idx+batch_size, size(x, 2));
batch_x = x(:, idx:idx_end);
idx = idx + batch_size;
if idx > size(x, 2)
done = true;
end
end