help-octave
[Top][All Lists]
Advanced

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

Re: Help to vectorize THIS loop


From: Macy
Subject: Re: Help to vectorize THIS loop
Date: Mon, 23 Sep 2013 08:02:54 -0700

Roberto,

Thank you for the script. For years I've been writing out the diff function 
manually, didn't even know it existed! Also, have never seen that idx = tn < t; 
technique. 

I do need the end points. Probably best to use extra terms, in other words, add 
two 'extra' endpoints outside the original 1 and end, then after determing the 
'new' 2:end-1 [which is the original size] throwing away 1 and end and returnig 
to the original size. To save variable space that may be the best way to do it.

Robert

--- address@hidden wrote:

From: Roberto Fabio Leonarduzzi <address@hidden>
To: Macy <address@hidden>
Cc: address@hidden
Subject: Re: Help to vectorize THIS loop
Date: Mon, 23 Sep 2013 11:36:23 -0300

Hi

2013/9/23 Macy <address@hidden>

>
> sigwn=sig;
> for i=2:hugenumber-1
>   if ( tn(i)<t(i) )
>    sigwn(i)=sig(i)-( sig(i)-sig(i-1) )*SR*( t(i)-tn)i) );
>   else
>    sigwn(i)=sig(i)+( sig(i+1)-sig(i) )*SR*( tn(i)-t)i) );
>  endif
> endfor
>
> any slick ways to vectorize this?
>

How about something like:

delta_sig_back = [0 diff(sig)];
delta_sig_forw = [0 diff(sig)(2 : end) 0]
idx = tn < t;
sigwn(idx) = sig(idx) + delta_sig_back(idx) .* SR .* (t(idx) - tn(idx));
idx = tn >= t;
sigwn(idx) = sig(idx) + delta_sig_forw(idx) .* SR .* (tn(idx) - t(idx));

?

I don't have octave installed in this computer so I couldn't try it out,
but I suppose something like that could work. If you don't want the
endpoints just erase them: sigwn=sigwn(2:end-1);

HTH,
Roberto




reply via email to

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