From: Melissa Stockman on
can some let me know why the following code run very fast
when i < 30 but then slows down considerably?

thanks
melissa

numPoints = 2000;
r(numPoints) = 0;
rindex = 1;
for i = 1 : numPoints
for j = i+1 : numPoints-i+1
theDiff = round(abs(theData(i) - theData(j)));
r(rindex) = theDiff/theData(i);
rindex = rindex + 1;
end
i
end
From: Adam Fisher on
"Melissa Stockman" <mel.stockman(a)hotmail.com> wrote in message <hrf316$6kb$1(a)fred.mathworks.com>...
> can some let me know why the following code run very fast
> when i < 30 but then slows down considerably?
>
> thanks
> melissa
>
> numPoints = 2000;
> r(numPoints) = 0;
> rindex = 1;
> for i = 1 : numPoints
> for j = i+1 : numPoints-i+1
> theDiff = round(abs(theData(i) - theData(j)));
> r(rindex) = theDiff/theData(i);
> rindex = rindex + 1;
> end
> i
> end


The processing time on this grows by the square of numPoints which makes it get bad in a hurry. I just typed this on the web page so it may have some syntax errors

if theData has numPoints of data ->

r = round(abs(theData(2:end)-theData(1:end-1)))./theData(2:end);

if you want to process the first numPoints of theData
r = round(abs(theData(2:numPoints)-theData(1:numPoints-1)))./theData(2:numPoints);





From: Adam Fisher on
"Adam Fisher" <adam.fisher(a)baesystems.com> wrote in message <hrf434$g64$1(a)fred.mathworks.com>...
> "Melissa Stockman" <mel.stockman(a)hotmail.com> wrote in message <hrf316$6kb$1(a)fred.mathworks.com>...
> > can some let me know why the following code run very fast
> > when i < 30 but then slows down considerably?
> >
> > thanks
> > melissa
> >
> > numPoints = 2000;
> > r(numPoints) = 0;
> > rindex = 1;
> > for i = 1 : numPoints
> > for j = i+1 : numPoints-i+1
> > theDiff = round(abs(theData(i) - theData(j)));
> > r(rindex) = theDiff/theData(i);
> > rindex = rindex + 1;
> > end
> > i
> > end
>
>
> The processing time on this grows by the square of numPoints which makes it get bad in a hurry. I just typed this on the web page so it may have some syntax errors
>
> if theData has numPoints of data ->
>
> r = round(abs(theData(2:end)-theData(1:end-1)))./theData(2:end);
>
> if you want to process the first numPoints of theData
> r = round(abs(theData(2:numPoints)-theData(1:numPoints-1)))./theData(2:numPoints);
>

I realized I didn't answer your question
The routine you wrote generates more than 2000 entries into r so eventually you have to start allocating memory.(it is trying to make almost 10^6 entries) Also if your code is correct nothing happens after i gets to 1001 since
for j = i+1 : numPoints-i+1
becomes
for j = 1002: 1000
From: Melissa Stockman on
hey thx 4 the so quick reply

melissa

"Adam Fisher" <adam.fisher(a)baesystems.com> wrote in message <hrf5e0$epf$1(a)fred.mathworks.com>...
> "Adam Fisher" <adam.fisher(a)baesystems.com> wrote in message <hrf434$g64$1(a)fred.mathworks.com>...
> > "Melissa Stockman" <mel.stockman(a)hotmail.com> wrote in message <hrf316$6kb$1(a)fred.mathworks.com>...
> > > can some let me know why the following code run very fast
> > > when i < 30 but then slows down considerably?
> > >
> > > thanks
> > > melissa
> > >
> > > numPoints = 2000;
> > > r(numPoints) = 0;
> > > rindex = 1;
> > > for i = 1 : numPoints
> > > for j = i+1 : numPoints-i+1
> > > theDiff = round(abs(theData(i) - theData(j)));
> > > r(rindex) = theDiff/theData(i);
> > > rindex = rindex + 1;
> > > end
> > > i
> > > end
> >
> >
> > The processing time on this grows by the square of numPoints which makes it get bad in a hurry. I just typed this on the web page so it may have some syntax errors
> >
> > if theData has numPoints of data ->
> >
> > r = round(abs(theData(2:end)-theData(1:end-1)))./theData(2:end);
> >
> > if you want to process the first numPoints of theData
> > r = round(abs(theData(2:numPoints)-theData(1:numPoints-1)))./theData(2:numPoints);
> >
>
> I realized I didn't answer your question
> The routine you wrote generates more than 2000 entries into r so eventually you have to start allocating memory.(it is trying to make almost 10^6 entries) Also if your code is correct nothing happens after i gets to 1001 since
> for j = i+1 : numPoints-i+1
> becomes
> for j = 1002: 1000