Vectorize this loop?

Matthias Brennwald matthias.brennwald at nagra.ch
Fri Oct 24 02:42:34 CDT 2008


Dear Octavers

Is it possible to get rid of the for loop in the below code by replacing
it by some vectorized code? I somehow think it is, but I can't see how.
Any ideas would be appreciated.

Thanks
Matthias


--------------------
point_count = round (rand(1000,1))*5 + 20; % this is just a dummy to
illustrate the problem.
N_vals  = sum (point_count);
N_scans = length (point_count);

scan_idx = repmat (NaN,N_vals,1);
ind = cumsum (point_count); ind = [0 ; ind];
for ii = 1:N_scans
	scan_idx (ind(ii)+1:ind(ii+1)) = ii;
end
--------------------



More information about the Help-octave mailing list