Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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 ]
Luca

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

Hi,
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

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

Here's some data:
numel (val(ind))~1-4
numel(maxima)~50k
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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.