The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Extreme optimization (can I vectorize this?)
Replies: 7   Last Post: Feb 26, 2013 12:50 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 77
Registered: 6/6/12
Extreme optimization (can I vectorize this?)
Posted: Feb 25, 2013 8:20 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I came up with the following code to perform a calculation, that involves a "for" loop on a very large vector.
This takes as much as 9 minutes on a very old laptop. It's not a real problem actually, but I was wondering whether it is possible to vectorize this and improve the performances or if it's already at the best (or near it).
Or if anybody can tell me how to speed this up in any way, just for the sake of "optimal programming".
Here's my variables:
val : 1D vector of (single) "values". size (val) ~400k,1
tim: 1D vector of timestamps of the previous values, same size as before.
sign: 1D logical vector, of true or falses, computed with some algorithm that tells me if "something is happening". Same size as before

clust = bwlabeln (sign);
maxima = zeros (max(sign(:)),1);
tMax = maxima;
for i=1:numel(maxima)
[maxima(i),I] = max(val(ind));
dummy = tim(ind);
tMax= dummy(I);

Here's some data:
numel (val(ind))~1-4
the thing taking most of the "long" time is (clust==i) with ~9ms, and ~2ms for all of the rest.

Thanks in advance!!

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.