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

Hello everybody.
I have a code which I found to be very slow, compared to what I expect.
I have two variables: mask (512x512x97 uint8) and maskC (512x512x97x3, uint8)

(actually the values in mask can be only between 0 and 6.)
I would like to give values to maskC according to the values in "mask".
Now I do this:
maskC = zeros (512,512,97,3,'uint8');
maskC(:,:,:,1) = (mask>1 &mask<3)*255;
maskC(:,:,:,2) = (mask>3 & mask<5)*255;
mask(:,:,:,3) = (mask>4 &mask<7)*255;

The output is:
It takes me 1 second (!!!!) to set the values of maskC in this way. On a top-speed PC.
What am I doing wrong? I would expect there should be some way to do this in less than 10ms! (like the creation of maskC in 0.3 ms!!)
I think I should be use logical indexing. But I don't see how in this case, where I add another dimension.

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.