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:
Cogent presentations slow after many hours of Matlab/Cogent operation

Subject: Cogent presentations slow after many hours of Matlab/Cogent operation

From: David Painter

Date: 21 Jan, 2010 12:17:04

Message: 1 of 3

Hi,

I'm running visual presentation experiments using the Cogent toolbox. I'm wondering why my experiment slows after Matlab has been running for a few hours. This problem can be fixed by restarting the computer. I'm not sure if it can also be fixed by restarting Matlab (I've created the program for a colleague). This can occur spontaneously or after the program has maintained the same display for a few minutes waiting for a response:

cflip
waitkeydown(inf);

This occurs after the experiment has run many times at normal speed. Each time a new experiment is run the Cogent window is closed (cgshut), Cogent timing is stopped (stop_cogent), and the Matlab workspace is cleared (clear).

The experiment basically runs in a series of loops that update the display. On each loop, my code checks if it is time to update the display. It is time to update the display if the current frame number matches a number in a 2 x 1 vector. When the time is right, a new image is called from one of four full-screen image arrays from Cogent buffers (cgdrawsprite). A few ellipses (cgellipse) and letters (cgtext) are called using a loop before the display is updated (cgflip).

At some points during the program user input is requested. User input and timing information are recorded into arrays of predetermined sizes. The data arrays are trivially small (~10,000 datapoints in all) compared to the information contained into the Cogent buffers. Literally nothing is being written to the command prompt at any stage.

Computer performance should not be a problem as very similar experiments have run on the same computer successfully without this issue. I don't know whether these other experiments have run for such long periods (many hours).

It seems like a memory issue, but the amount of information in memory should be basically constant. Accurate timing and confidence in the program are essential. Any ideas?

Thanks,

David

Subject: Cogent presentations slow after many hours of Matlab/Cogent operation

From: Steven Lord

Date: 21 Jan, 2010 14:48:45

Message: 2 of 3


"David Painter" <david.ross.painter@gmail.com> wrote in message
news:hj9gk0$29p$1@fred.mathworks.com...
> Hi,
>
> I'm running visual presentation experiments using the Cogent toolbox. I'm
> wondering why my experiment slows after Matlab has been running for a few
> hours. This problem can be fixed by restarting the computer. I'm not sure
> if it can also be fixed by restarting Matlab (I've created the program for
> a colleague). This can occur spontaneously or after the program has
> maintained the same display for a few minutes waiting for a response:
>
> cflip
> waitkeydown(inf);
>
> This occurs after the experiment has run many times at normal speed. Each
> time a new experiment is run the Cogent window is closed (cgshut), Cogent
> timing is stopped (stop_cogent), and the Matlab workspace is cleared
> (clear).
>
> The experiment basically runs in a series of loops that update the
> display. On each loop, my code checks if it is time to update the display.
> It is time to update the display if the current frame number matches a
> number in a 2 x 1 vector. When the time is right, a new image is called
> from one of four full-screen image arrays from Cogent buffers
> (cgdrawsprite). A few ellipses (cgellipse) and letters (cgtext) are called
> using a loop before the display is updated (cgflip).

Are you _adding_ new items like an image or ellipse to the screen or are you
_replacing_ what's already there?

figure
plot(1:10, rand(1, 10));
hold on
nc_add = zeros(1, 100);
for k = 1:100
    nc_add(k) = numel(get(gca, 'Children'));
    set(allchild(gca), 'Visible', 'off')
    plot(1:10, rand(1, 10));
end

figure
plot(1:10, rand(1, 10));
nc_replace = zeros(1, 100);
for k = 1:100
    nc_replace(k) = numel(get(gca, 'Children'));
    set(allchild(gca), 'Visible', 'off')
    plot(1:10, rand(1, 10));
end
nc_add, nc_replace

Each graph _appears_ to have only one line on it, but the first has a
hundred items on it that consume some memory and the second only has one
item. [Instead of making the previously displayed items invisible in the
first example, imagine plotting each new item "on top" of the preexisting
items, concealing them.]

If that doesn't indicate a cause for this problem, you could run your
program using MATLAB Profiler (see HELP PROFILE) to locate any potential
bottlenecks.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Cogent presentations slow after many hours of Matlab/Cogent operation

From: David Painter

Date: 23 Feb, 2010 11:53:03

Message: 3 of 3

"Steven Lord" <slord@mathworks.com> wrote in message <hj9pg6$2an$1@fred.mathworks.com>...
>
> "David Painter" <david.ross.painter@gmail.com> wrote in message
> news:hj9gk0$29p$1@fred.mathworks.com...
> > Hi,
> >
> > I'm running visual presentation experiments using the Cogent toolbox. I'm
> > wondering why my experiment slows after Matlab has been running for a few
> > hours. This problem can be fixed by restarting the computer. I'm not sure
> > if it can also be fixed by restarting Matlab (I've created the program for
> > a colleague). This can occur spontaneously or after the program has
> > maintained the same display for a few minutes waiting for a response:
> >
> > cflip
> > waitkeydown(inf);
> >
> > This occurs after the experiment has run many times at normal speed. Each
> > time a new experiment is run the Cogent window is closed (cgshut), Cogent
> > timing is stopped (stop_cogent), and the Matlab workspace is cleared
> > (clear).
> >
> > The experiment basically runs in a series of loops that update the
> > display. On each loop, my code checks if it is time to update the display.
> > It is time to update the display if the current frame number matches a
> > number in a 2 x 1 vector. When the time is right, a new image is called
> > from one of four full-screen image arrays from Cogent buffers
> > (cgdrawsprite). A few ellipses (cgellipse) and letters (cgtext) are called
> > using a loop before the display is updated (cgflip).
>
> Are you _adding_ new items like an image or ellipse to the screen or are you
> _replacing_ what's already there?
>
> figure
> plot(1:10, rand(1, 10));
> hold on
> nc_add = zeros(1, 100);
> for k = 1:100
> nc_add(k) = numel(get(gca, 'Children'));
> set(allchild(gca), 'Visible', 'off')
> plot(1:10, rand(1, 10));
> end
>
> figure
> plot(1:10, rand(1, 10));
> nc_replace = zeros(1, 100);
> for k = 1:100
> nc_replace(k) = numel(get(gca, 'Children'));
> set(allchild(gca), 'Visible', 'off')
> plot(1:10, rand(1, 10));
> end
> nc_add, nc_replace
>
> Each graph _appears_ to have only one line on it, but the first has a
> hundred items on it that consume some memory and the second only has one
> item. [Instead of making the previously displayed items invisible in the
> first example, imagine plotting each new item "on top" of the preexisting
> items, concealing them.]
>
> If that doesn't indicate a cause for this problem, you could run your
> program using MATLAB Profiler (see HELP PROFILE) to locate any potential
> bottlenecks.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Thanks Steve. You are pretty much on the money.

Worked out the problem was delayed screen refreshes due to high draw times on graphics. The computation time before refresh was close to "threshold" for skipping a refresh and would pass threshold after the computer had been running for a while. I solved the problem by moving the drawing routines outside the loop. :D

Easy.

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