Search All of the Math Forum:

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

Topic: speeding up assigning values to a matrix
Replies: 7   Last Post: Apr 8, 2013 3:52 AM

 Messages: [ Previous | Next ]
 kinor Posts: 184 Registered: 11/19/09
Re: speeding up assigning values to a matrix
Posted: Apr 5, 2013 11:17 AM

"Luca " <l.presottoRE@MOVE.campus.unimib.NOTit> wrote in message <kjmjsi\$amg\$1@newscl01ah.mathworks.com>...
> 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:
> ts=tic;
> toc(ts);
> ts=tic;
> toc(ts);
> ts=tic;
> toc(ts);
> ts=tic;
> toc(ts);
>
> The output is:
> 0.0003
> 0.29
> 0.31
> 0.29
> 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.

Hi Luca,

this is faster but slower than your achieved 10 ms, i wonder if you get it that fast.
ts=tic;
toc(ts);
ts=tic;
toc(ts);
ts=tic;
toc(ts);
tic
toc

hth
kinor

Date Subject Author
4/5/13 Luca
4/5/13 kinor
4/5/13 Luca
4/5/13 kinor
4/5/13 Luca
4/5/13 dpb
4/5/13 Luca
4/8/13 kinor