On Wed, Oct 3, 2012 at 12:17 PM, Torbjörn Rathsman <torbj...@student.chalmers.se> wrote: > 2012-10-02 22:12, Juan Pablo Carbajal skrev: >> On Tue, Oct 2, 2012 at 9:00 PM, Torbjörn Rathsman >> <torbj...@student.chalmers.se> wrote: >>> Is this kind of thing possible to do without do it in a loop? >>> >>> notes=[1 1 0 1 1 1 0 1 1 0 1 0]'; >>> x=12.*log(f./440)./log(2); >>> spectrum=spectrum.*cos(pi.*x).^16.* notes( mod(round(x),12) + 1 ); >>> >>> f is a vector of 10^7 elements and I want to take each computed index and >>> generate corresponding value from notes. >>> _______________________________________________ >>> Help-octave mailing list >>> help-oct...@octave.org >>> https://mailman.cae.wisc.edu/listinfo/help-octave >> Can you give more details? I do not see a loop. >> I see that you are multiplying spectrum by something and then saving >> it back into spectrum. What is the initial value of spectrum. >> >> Sorry for not understanding. >> >> > Implemented using a loop: > > notes=[1 1 0 1 1 1 0 1 1 0 1 0]'; > > for k=1:N %N huge > > x=12.*log(f(k)./440)./log(2); > spectrum(k)=spectrum(k).*cos(pi.*x).^16.* notes( mod(round(x),12) + 1 ); > > end > > I want to implement the same thing without a loop. >
Hi, Always keep the mailing list in CC. Here is my attempt tp vectorize your code. I expanded it so that you understand all the stages. You do not need to create all those intermediate variables http://agora.octave.org/snippet/hchr/ Note that I am assuming that the variable spectrum exists, it is a column and has length N. Hope this helps. -- M. Sc. Juan Pablo Carbajal ----- PhD Student University of Zürich http://ailab.ifi.uzh.ch/carbajal/ ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev