From: Walter Roberson on 10 Aug 2010 00:03 Juliette Salexa wrote: > The forloop looks like: > > for i=1:100 > A=reshape(bsxfun(@times,reshape(sum(reshape(A,[],N^2),2),1,[]),I),[],1); > B(i)=summation of certain elements of A > end The calculation of A is not dependent upon the value of i, and thus the entire calculation of A can be taken out of the loop.
From: Juliette Salexa on 10 Aug 2010 07:47 Walter Roberson <roberson(a)hushmail.com> wrote in message <sc48o.3830$1v3.2484(a)newsfe20.iad>... > Juliette Salexa wrote: > > > The forloop looks like: > > > > for i=1:100 > > A=reshape(bsxfun(@times,reshape(sum(reshape(A,[],N^2),2),1,[]),I),[],1); > > B(i)=summation of certain elements of A > > end > > The calculation of A is not dependent upon the value of i, and thus the > entire calculation of A can be taken out of the loop. Hello, I'm not sure what you mean here. My forloop is like: i=1:100 A=A+A^3 B(i)=A end The calculation doesn't explicitly depend on i, but if I take it out of the forloop, I won't be able to get the next value of B (i think..)
From: Matt Fig on 10 Aug 2010 09:41 Walter Roberson <roberson(a)hushmail.com> wrote in message > The calculation of A is not dependent upon the value of i, and thus the > entire calculation of A can be taken out of the loop. Walter, Though the value of A is not dependent directly on the loop index, the value of A may change with each index since the value of A at each iteration is dependent on the value of A in the previous iteration. Juliette, I think we may need to know more about what goes on with B in order to help optimize your code. Do the values in A tend asymptotically towards a value, or oscillate about some value?
From: Andy on 10 Aug 2010 10:03 > Although I'm convinced that I remember seeing a blog post by Loren Shure which described how to avoid this, but for some reason I can't find it anymore =( Could it have been one of these?: http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/ http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/ http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/ I also agree with Matt Fig that we need more information about B. If you only need certain elements of A in each iteration, it's possible there's a way to calculate only those elements, which could save lots of time and space.
First
|
Prev
|
Pages: 1 2 3 Prev: remove a specific frequency from emg signal Next: remove a specific frequency from emg signal |