Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Updating part of an array

Subject: Updating part of an array

From: Mark

Date: 10 Dec, 2010 15:22:05

Message: 1 of 4

I'm updating part of an array, but it appears to be slow. Any ideas on how to speed this up:

tic
newmask = min( mask( minX_mask:maxX_mask, minY_mask:maxY_mask, minSlice_mask:maxSlice_mask) , T( minX_tempvals:maxX_tempvals,minY_tempvals:maxY_tempvals) );
toc
tic
mask( minX_mask:maxX_mask, minY_mask:maxY_mask, minSlice_mask:maxSlice_mask) = newmask;
toc

it appears filling a section in a larger array is the slow bit

Elapsed time is 0.000033 seconds.
Elapsed time is 0.327990 seconds.

Any suggestions

Subject: Updating part of an array

From: Sean de

Date: 10 Dec, 2010 15:31:04

Message: 2 of 4

"Mark " <mark.gooding@gmail.com> wrote in message <idtgis$6rt$1@fred.mathworks.com>...
> I'm updating part of an array, but it appears to be slow. Any ideas on how to speed this up:
>
> tic
> newmask = min( mask( minX_mask:maxX_mask, minY_mask:maxY_mask, minSlice_mask:maxSlice_mask) , T( minX_tempvals:maxX_tempvals,minY_tempvals:maxY_tempvals) );
> toc
> tic
> mask( minX_mask:maxX_mask, minY_mask:maxY_mask, minSlice_mask:maxSlice_mask) = newmask;
> toc
>
> it appears filling a section in a larger array is the slow bit
>
> Elapsed time is 0.000033 seconds.
> Elapsed time is 0.327990 seconds.
>
> Any suggestions

If you haven't: store your code in a function and call it a couple of times, then check the times to see if they've evened out.

Subject: Updating part of an array

From: Mark

Date: 10 Dec, 2010 15:42:07

Message: 3 of 4

> If you haven't: store your code in a function and call it a couple of times, then check the times to see if they've evened out.

The results are relatively constant over multiple runs (see below). The updating part is much slower than the calculation part.

Elapsed time is 0.000031 seconds. - calculation
Elapsed time is 0.306914 seconds. - array update
Elapsed time is 0.000033 seconds. - calculation
Elapsed time is 0.298592 seconds. - array update
Elapsed time is 0.000032 seconds. - calculation
Elapsed time is 0.329876 seconds. - array update etc
Elapsed time is 0.000037 seconds.
Elapsed time is 0.294380 seconds.
Elapsed time is 0.000033 seconds.
Elapsed time is 0.344772 seconds.
Elapsed time is 0.000117 seconds.
Elapsed time is 0.324890 seconds.
Elapsed time is 0.000032 seconds.
Elapsed time is 0.305353 seconds.

Subject: Updating part of an array

From: Mark

Date: 13 Dec, 2010 10:46:04

Message: 4 of 4

bump. Please help if you can!

"Mark " <mark.gooding@gmail.com> wrote in message <idthof$su2$1@fred.mathworks.com>...
> > If you haven't: store your code in a function and call it a couple of times, then check the times to see if they've evened out.
>
> The results are relatively constant over multiple runs (see below). The updating part is much slower than the calculation part.
>
> Elapsed time is 0.000031 seconds. - calculation
> Elapsed time is 0.306914 seconds. - array update
> Elapsed time is 0.000033 seconds. - calculation
> Elapsed time is 0.298592 seconds. - array update
> Elapsed time is 0.000032 seconds. - calculation
> Elapsed time is 0.329876 seconds. - array update etc
> Elapsed time is 0.000037 seconds.
> Elapsed time is 0.294380 seconds.
> Elapsed time is 0.000033 seconds.
> Elapsed time is 0.344772 seconds.
> Elapsed time is 0.000117 seconds.
> Elapsed time is 0.324890 seconds.
> Elapsed time is 0.000032 seconds.
> Elapsed time is 0.305353 seconds.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us