How do I replace this for-loop?

de Almeida, Valmor F. dealmeidav at ornl.gov
Sat Jul 5 13:24:30 CDT 2008


Does this give you any speed up?

    output(n(:,1),n(:,2)) = 1;



--
Valmor


> -----Original Message-----
> From: Robert Macy [mailto:macy at california.com]
> Sent: Friday, July 04, 2008 5:49 PM
> To: help-octave at octave.org
> Subject: How do I replace this for-loop?
> 
> What's the best way to replace this for-loop?
> 
> Given an array, n, of datapoints, such that:
> 
> >> size(n)
> rows = 27000
> columns = 2
> 
> where n(:,1) are all the integer x values, and
> n(:,2) are all the integer y values,
> both integer values are in the range of 1 to 101
> 
> I slowly did it this way:
> 
> output=zeros(101,101);
> for i=1:27000
>   output( n(i,1),n(i,2) ) = output( n(i,1),n(i,2) ) + 1;
> endfor
> 
> as you all know this is fairly slow.
> What's a simple way to replace this for-loop?
> 
> Robert
> 
> _______________________________________________
> Help-octave mailing list
> Help-octave at octave.org
> https://www.cae.wisc.edu/mailman/listinfo/help-octave



More information about the Help-octave mailing list