2 ms·
I would reshape s since foo would anyway be vectorized. You could also do for i = 1:10:length(s) foo(s(i:i+9)) endfor With numpy the 9 turns into a 10 b
by SiempreViernes 8y ago
I would reshape s since foo would anyway be vectorized.
You could also do
for i = 1:10:length(s)
foo(s(i:i+9))
endfor
With numpy the 9 turns into a 10 by the design choice that s[a:b] only goes to s[b-1], this is sometimes convenient, and sometimes it costs a +1.
- Serow225 8y agoYes probably reshape would be the natural MATLAB way to do it. Under the hood it doesn't change the memory allocation of the mxArray, just the metadata -- so the reshape takes virtually no time. But if you wanted to do the loop like that, I think you could simplify that to 1:10:end , btw. Also there is a blockproc function that will do it for you, you just pass in the chunk size and a function handle to 's', but it's in the Image Processing toolbox