help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with vectorizing a for loop


From: Rick T
Subject: Re: help with vectorizing a for loop
Date: Tue, 4 Oct 2011 10:46:48 -1000



On Mon, Oct 3, 2011 at 8:57 AM, Thomas Weber <address@hidden> wrote:
On Mon, Oct 03, 2011 at 12:09:58AM -1000, Rick T wrote:
> Greetings All
>
> I have a for loop that reads an array but I would like to vectorize it to
> see if will improve speed. at the moment the for loop takes about 7 mins any
> ideas to speed this up
>
> The array called inner_freq has three columns made up of
> amplitude,frequency, and phase
>
> for ii=1:1:length(inner_freq)-1
>
>  aa_sig_rebuilt=inner_freq(ii,2)*cos(2*pi*t*inner_freq(ii,1)+inner_freq(ii,3));
>      aa_sig_combined=aa_sig_combined+aa_sig_rebuilt;
> end;

I might be missing something here, but how about

col1 = inner_freq(:, 1);
col2 = inner_freq(:, 2);
col3 = inner_freq(:, 3);

aa_sig_combined = sum(col2 .* cos(2*pi*t*col1 + col3));

       Thomas


I tried all three suggested options I either ran into a non conformant error or memory exhausted due to my arrays being to large.  The t_rebuilt array is 1x15679 and the inner_freq array is 8193x3.  Any other ideas I can try to speed this for loop up? I think I may have to many values in the array for vectorization to work.
--


reply via email to

[Prev in Thread] Current Thread [Next in Thread]