From: Melissa Stockman on 30 Apr 2010 13:12 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 30 Apr 2010 13:30 "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 30 Apr 2010 13:53 "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 30 Apr 2010 14:04 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
|
Pages: 1 Prev: Binary nonlinear optimization Next: output variables - GUIDE - varargout |