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: speeding up assigning values to a matrix
Replies: 7   Last Post: Apr 8, 2013 3:52 AM

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
Re: speeding up assigning values to a matrix
Posted: Apr 5, 2013 3:24 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I think I've come to the ultimate optimization.
(now I'm at home with a 5 years old laptop, so the performance are way slower than on the verrifast office PC).
This time the quoted times are on this laptop, so definitely longer
I do this:
maskR= zeros(size(mask),'uint8'); %create 3 RGB separate masks of uint8, same size of the original
toc(ts); %less than 1 ms
toc(ts); %180ms
maskG(mask==1|mask==2) = 255;
maskB(mask==2|mask==3) = 255;
%180ms each
maskC = cat(4,maskR,maskG,maskB);
toc(ts); %140 ms

instead doing;
maskC = zeros (512,512,87,3,'uint8');
maskC(:,:,:,1)= uint8((mask==1))*255;
takes 800ms, 4 times more for each "color". And this is the second best optimization.

The original code
maskC(:,:,:,1) = (mask==1)*255,
takes, on this pc, 1.2 s.
Therefore I've sped up by a factor 10!
I don't think I can get any better. Anyway I think the problem in this "long" execution times are in the fact that I'm dealing with a 76MB matrix...

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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.