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: Roberto Fabio Leonarduzzi
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]