| MATLAB Central > MATLAB Newsreader > Help speeding up/replacing loops |
|
|
|
Subject: Help speeding up/replacing loops From: James Wright Date: 16 Jun, 2009 16:15:04 Message: 1 of 31 |
|
I've written some code, however it takes forever (several days) to run for larger values. Can anyone with more experience in matlab help me with the issue?? I understand vectorization is the way forward, but I'm unaware of how to do this for most of my loops. |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 16 Jun, 2009 16:36:02 Message: 2 of 31 |
|
I haven't looked over your code thoroughly, but one thing stands out immediately. Are you creating strings for comments? If so, you would be much better off to do this: |
|
Subject: Help speeding up/replacing loops From: Steven Lord Date: 16 Jun, 2009 16:56:54 Message: 3 of 31 |
|
|
|
Subject: Help speeding up/replacing loops From: James Wright Date: 16 Jun, 2009 17:24:01 Message: 4 of 31 |
|
"Steven Lord" <slord@mathworks.com> wrote in message <h18irl$1um$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 16 Jun, 2009 17:49:01 Message: 5 of 31 |
|
Is it even possible to replace loops like: |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 16 Jun, 2009 18:43:01 Message: 6 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> wrote in message <h18lud$rpl$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 16 Jun, 2009 23:57:01 Message: 7 of 31 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h18p3l$3u1$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: Steven Lord Date: 17 Jun, 2009 03:24:50 Message: 8 of 31 |
|
|
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 12:41:01 Message: 9 of 31 |
|
Thanks for all the help so far, really appreciate it! This is an update of what my code looks like now, which I think is quite a bit better than before, but there's still a few points I could do with some help on. |
|
Subject: Help speeding up/replacing loops From: tpl@eng.cam.ac.uk (Tim Love) Date: 17 Jun, 2009 13:06:09 Message: 10 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> writes: |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 14:58:02 Message: 11 of 31 |
|
tpl@eng.cam.ac.uk (Tim Love) wrote in message <h1apo1$kjc$1@gemini.csx.cam.ac.uk>... |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 17 Jun, 2009 15:20:05 Message: 12 of 31 |
|
I don't see an easy vectorization of this snippet. However, I am wondering why you have not taken the good advice to pre-allocate your arrays before the loops? This can lead to speed increases which rival those of vectorization in some cases! For example, put this in a file and run the file: |
|
Subject: Help speeding up/replacing loops From: tpl@eng.cam.ac.uk (Tim Love) Date: 17 Jun, 2009 15:29:06 Message: 13 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> writes: |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 16:07:02 Message: 14 of 31 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h1b1j5$kks$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 16:20:19 Message: 15 of 31 |
|
Maybe finding a way to vectorize that isn't worth the time it'll take. The main time consumer is most probably this loop anyway. |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 17 Jun, 2009 16:26:03 Message: 16 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> wrote in message |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 16:49:01 Message: 17 of 31 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h1b5er$8td$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 17 Jun, 2009 18:22:01 Message: 18 of 31 |
|
By far your major time hog is this: |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 17 Jun, 2009 21:48:01 Message: 19 of 31 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h1bc89$83t$1@fred.mathworks.com>... |
|
On Jun 17, 2:48 pm, "James Wright" <jameswright1...@yahoo.co.uk> |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 18 Jun, 2009 13:38:05 Message: 21 of 31 |
|
Peter <petersamsimon2@hotmail.com> wrote in message <5a16f286-988c-4681-92d0-33f9a19062a8@d25g2000prn.googlegroups.com>... |
|
On Jun 18, 6:38 am, "James Wright" <jameswright1...@yahoo.co.uk> |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 19 Jun, 2009 22:23:02 Message: 23 of 31 |
|
Peter <petersamsimon2@hotmail.com> wrote in message <11be7337-b5a7-4449-89c8-b2545c852be9@y6g2000prf.googlegroups.com>... |
|
Subject: Help speeding up/replacing loops From: Matt Fig Date: 19 Jun, 2009 22:44:02 Message: 24 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> wrote in message |
|
On Jun 19, 3:44 pm, "Matt Fig" <spama...@yahoo.com> wrote: |
|
Subject: Help speeding up/replacing loops From: Bruno Luong Date: 20 Jun, 2009 07:13:01 Message: 26 of 31 |
|
"Matt Fig" <spamanon@yahoo.com> wrote in message <h1bc89$83t$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: Bruno Luong Date: 20 Jun, 2009 12:59:02 Message: 27 of 31 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h1i25t$6i$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: Bruno Luong Date: 20 Jun, 2009 15:50:03 Message: 28 of 31 |
|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h1imem$b5f$1@fred.mathworks.com>... |
|
Subject: Help speeding up/replacing loops From: Bruno Luong Date: 20 Jun, 2009 18:42:01 Message: 29 of 31 |
|
Matlab CONV does not seem to use FFT (contrary to the doc, since it is very slow). I use my own FFT-based convolution; and here is a timing. |
|
Subject: Help speeding up/replacing loops From: James Wright Date: 22 Jun, 2009 08:52:01 Message: 30 of 31 |
|
Thanks for all the help, I think I've finally got something that will be quick enough (still a few days but better than the 125 it would have taken before) and accurate enough. |
|
Subject: Help speeding up/replacing loops From: Oleg Komarov Date: 27 Jun, 2009 12:31:01 Message: 31 of 31 |
|
"James Wright" <jameswright1001@yahoo.co.uk> wrote in message <h1ngnh$68o$1@fred.mathworks.com>... |
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
| Tag Activity for This Thread | ||
|---|---|---|
| Tag | Applied By | Date/Time |
| loops | James Wright | 16 Jun, 2009 12:19:05 |
| faster | James Wright | 16 Jun, 2009 12:19:05 |
| speeding up | James Wright | 16 Jun, 2009 12:19:05 |
| vectorization | James Wright | 16 Jun, 2009 12:19:05 |
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.
Contact us at files@mathworks.com