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: Wed, 5 Oct 2011 08:11:53 -1000

Using this code 

inner_freq = rand(8193,3);
t = rand(1,15679);
aa_sig_combined = 0;

tic,
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;
toc


Running on Ubuntu 10.04 64bit octave 3.2.4 using i3 processor using 6 gig of ram it takes 6 seconds

Running in a Virtual box Machine using i3 processor Compiled Octave 3.4.2 from source using ubuntu 10.04 32bit using 3gig of ram it takes 9 seconds

On Wed, Oct 5, 2011 at 6:22 AM, Martin Helm <address@hidden> wrote:
Am Dienstag, den 04.10.2011, 16:20 -1000 schrieb Rick T:
> Thanks for all the great help and code I've got it down to 9 seconds
> still get an error "nonconformant arguments (op1 is 1x15679, op2 is
> 8193x1)"
> using the code below but more than likely I would run into memory
> errors latter on down the line since the arrays will only get bigger
> not smaller.
>
>
> clear all
> inner_freq = rand(8193,3);
> t = rand(1,15679);
> aa_sig_combined = 0;
> tic,
> aa_sig_combined2 = sum(inner_freq(:, 2)*cos (2*pi*t.*inner_freq(:, 1)+
> inner_freq(:, 3)));
> toc
>
>
> But 9 seconds is nothing to shake a stick at
I think you misinterpret that result, of course this will give you an
error since you used the _expression_ which was for a scalar t and not the
one which was meant for a non scalar t.

What really surprises me is the 9 sec you mention, using that code it
tells me after a few milliseconds (again this is on a simple netbook!
not on my PC which is roughly 10-20 times faster depending on what is
done) that there is an error. That sounds very strange.

What machine are you running on (RAM, CPU, operating system) and what
octave version?






reply via email to

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