Thread Subject: Running a function in the background

Subject: Running a function in the background

From: swgillan

Date: 27 Sep, 2009 04:15:13

Message: 1 of 10

I was recently reviewing a webinar on large datasets, and the person
running the webinar ran a function called WriteMalloc (or something
like that).

Essentially what it did was it was a plot window that updated every
second with the amount of memory used by the matlab session.

I am looking at writing something similar, but I have never seen a
figure get updated and run parallel with inputting in the command
window. Does anyone know how this might be done?

This isn't vital, but it was one of those things that I have never
seen before, and think it could be really handy.

Subject: Running a function in the background

From: Steven Lord

Date: 28 Sep, 2009 14:16:43

Message: 2 of 10


"swgillan" <swgillan@gmail.com> wrote in message
news:f48e68c5-54f4-41b8-9843-0d8c995366b0@i4g2000prm.googlegroups.com...
>I was recently reviewing a webinar on large datasets, and the person
> running the webinar ran a function called WriteMalloc (or something
> like that).
>
> Essentially what it did was it was a plot window that updated every
> second with the amount of memory used by the matlab session.
>
> I am looking at writing something similar, but I have never seen a
> figure get updated and run parallel with inputting in the command
> window. Does anyone know how this might be done?
>
> This isn't vital, but it was one of those things that I have never
> seen before, and think it could be really handy.

I don't know specifically what was being used in the webinar you described,
but perhaps that function was using a TIMER object to perform the updates,
or it set the *DataSource properties of a line and used REFRESHDATA to force
it to update?

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

Subject: Running a function in the background

From: TideMan

Date: 28 Sep, 2009 19:01:07

Message: 3 of 10

On Sep 27, 5:15 pm, swgillan <swgil...@gmail.com> wrote:
> I was recently reviewing a webinar on large datasets, and the person
> running the webinar ran a function called WriteMalloc (or something
> like that).
>
> Essentially what it did was it was a plot window that updated every
> second with the amount of memory used by the matlab session.
>
> I am looking at writing something similar, but I have never seen a
> figure get updated and run parallel with inputting in the command
> window. Does anyone know how this might be done?
>
> This isn't vital, but it was one of those things that I have never
> seen before, and think it could be really handy.

If you're using Linux, Conky can do this for you.
http://conky.sourceforge.net/

Subject: Running a function in the background

From: swgillan

Date: 30 Sep, 2009 07:09:39

Message: 4 of 10

I wasn't quite sure exactly what they did (the flashed the code, and
that was it).

Essentially, they had a figure window docked and at the same time in
the command window they were doing basic matrix operations showing how
the memory is managed in matlab (hence the updated docked figure
showing the line graph of system.memory, or something like that as
time elapsed).

Basically, that is how they were using it, and I was curious about
looking at the code (it wasn't posted).

I can try and view the topic for anyway else to have a look at it. I
have seen this demo twice before, once in person here at UVIC and
again online.

Steven Gillan

On Sep 28, 7:16 am, "Steven Lord" <sl...@mathworks.com> wrote:
> "swgillan" <swgil...@gmail.com> wrote in message
>
> news:f48e68c5-54f4-41b8-9843-0d8c995366b0@i4g2000prm.googlegroups.com...
>
> >I was recently reviewing a webinar on large datasets, and the person
> > running the webinar ran a function called WriteMalloc (or something
> > like that).
>
> > Essentially what it did was it was a plot window that updated every
> > second with the amount of memory used by the matlab session.
>
> > I am looking at writing something similar, but I have never seen a
> > figure get updated and run parallel with inputting in the command
> > window. Does anyone know how this might be done?
>
> > This isn't vital, but it was one of those things that I have never
> > seen before, and think it could be really handy.
>
> I don't know specifically what was being used in the webinar you described,
> but perhaps that function was using a TIMER object to perform the updates,
> or it set the *DataSource properties of a line and used REFRESHDATA to force
> it to update?
>
> --
> Steve Lord
> sl...@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ:http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Running a function in the background

From: swgillan

Date: 30 Sep, 2009 07:10:27

Message: 5 of 10

On Sep 28, 12:01 pm, TideMan <mul...@gmail.com> wrote:
> On Sep 27, 5:15 pm,swgillan<swgil...@gmail.com> wrote:
>
> > I was recently reviewing a webinar on large datasets, and the person
> > running the webinar ran a function called WriteMalloc (or something
> > like that).
>
> > Essentially what it did was it was a plot window that updated every
> > second with the amount of memory used by the matlab session.
>
> > I am looking at writing something similar, but I have never seen a
> > figure get updated and run parallel with inputting in the command
> > window. Does anyone know how this might be done?
>
> > This isn't vital, but it was one of those things that I have never
> > seen before, and think it could be really handy.
>
> If you're using Linux, Conky can do this for you.http://conky.sourceforge.net/

I am not looking at the specific Malloc and memory case, but more
having the figure updating in the background, while I work in the
command window.

Subject: Running a function in the background

From: swgillan

Date: 30 Sep, 2009 07:39:09

Message: 6 of 10

I found the webinar in question: Large Data Sets in Matlab, presented
by Mike Agostini.

I have since emailed him directly finding out what I wanted. If you
are curious, it was at the 20:00 mark that I was interested in.

Subject: Running a function in the background

From: Steven Lord

Date: 30 Sep, 2009 14:04:09

Message: 7 of 10


"swgillan" <swgillan@gmail.com> wrote in message
news:105ea682-707d-4779-b613-cd1c8bb7cfe0@e4g2000prn.googlegroups.com...
>I found the webinar in question: Large Data Sets in Matlab, presented
> by Mike Agostini.
>
> I have since emailed him directly finding out what I wanted. If you
> are curious, it was at the 20:00 mark that I was interested in.

If I were implementing something like that, I'd use a Timer object to
periodically run a function that updates the figure. As a small example:

function comet2(delayS, x, y)
% COMET2 Display points in a line with a delay between each point display
%
% COMET2(delayS, x, y) displays each of the points represented by elements
% in the x and y vectors with a delay of delayS seconds between each point.

if ~isequal(numel(x), numel(y))
    error('comet2:invalidCoords', 'The x and y inputs must have the same
number of elements.');
end

if ~isreal(delayS) || delayS <= 0 || ~isscalar(delayS) || ~isfinite(delayS)
    error('comet2:invalidDelayS', 'The delay must be a real finite positive
scalar.');
end

h = line(NaN, NaN);
axis([min(x) max(x) min(y) max(y)])
set(h, 'UserData', 1);

t = timer('TasksToExecute', numel(x), ...
    'ExecutionMode', 'fixedRate', ...
    'StartDelay', 0, ...
    'Period', delayS);
set(t, 'TimerFcn', @(varargin) updatePlot(h, x, y, t), ...
    'StopFcn', @(varargin) delete(t));
start(t);

function updatePlot(h, x, y, t)
try
    nextPoint = get(h, 'UserData');
    set(h, 'XData', x(1:nextPoint), 'YData', y(1:nextPoint), 'UserData',
nextPoint+1);
catch %#ok<CTCH>
    stop(t);
end

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

Subject: Running a function in the background

From: swgillan

Date: 1 Oct, 2009 02:52:47

Message: 8 of 10

Thanks for sharing that, I have never used a lot of the gcf stuff, so
I will look over that code and take what I can from it. I was also
passed on the watch_malloc code from the presenter, so I should be
able to figure out how things were done!

Thanks for all the help.

Now all I need is to find out why 3d plotting is messed up in Ubuntu
9.04 (I think it is an intel graphics driver problem).

Regards,

Steven Gillan
>
> If I were implementing something like that, I'd use a Timer object to
> periodically run a function that updates the figure.  As a small example:
>
> function comet2(delayS, x, y)
> % COMET2 Display points in a line with a delay between each point display
> %
> % COMET2(delayS, x, y) displays each of the points represented by elements
> % in the x and y vectors with a delay of delayS seconds between each point.
>
> if ~isequal(numel(x), numel(y))
>     error('comet2:invalidCoords', 'The x and y inputs must have the same
> number of elements.');
> end
>
> if ~isreal(delayS) || delayS <= 0 || ~isscalar(delayS) || ~isfinite(delayS)
>     error('comet2:invalidDelayS', 'The delay must be a real finite positive
> scalar.');
> end
>
> h = line(NaN, NaN);
> axis([min(x) max(x) min(y) max(y)])
> set(h, 'UserData', 1);
>
> t = timer('TasksToExecute', numel(x), ...
>     'ExecutionMode', 'fixedRate', ...
>     'StartDelay', 0, ...
>     'Period', delayS);
> set(t, 'TimerFcn', @(varargin) updatePlot(h, x, y, t), ...
>     'StopFcn', @(varargin) delete(t));
> start(t);
>
> function updatePlot(h, x, y, t)
> try
>     nextPoint = get(h, 'UserData');
>     set(h, 'XData', x(1:nextPoint), 'YData', y(1:nextPoint), 'UserData',
> nextPoint+1);
> catch %#ok<CTCH>
>     stop(t);
> end
>
> --
> Steve Lord
> sl...@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ:http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Running a function in the background

From: Simon

Date: 17 Nov, 2009 09:28:01

Message: 9 of 10

swgillan <swgillan@gmail.com> wrote in message <43fc2ee2-059a-4a4f-8455-1adf0388a02d@w37g2000prg.googlegroups.com>...
> Thanks for sharing that, I have never used a lot of the gcf stuff, so
> I will look over that code and take what I can from it. I was also
> passed on the watch_malloc code from the presenter, so I should be
> able to figure out how things were done!
>
> Thanks for all the help.
>
> Now all I need is to find out why 3d plotting is messed up in Ubuntu
> 9.04 (I think it is an intel graphics driver problem).
>
> Regards,
>
> Steven Gillan
> >
> > If I were implementing something like that, I'd use a Timer object to
> > periodically run a function that updates the figure. ?As a small example:
> >
> > function comet2(delayS, x, y)
> > % COMET2 Display points in a line with a delay between each point display
> > %
> > % COMET2(delayS, x, y) displays each of the points represented by elements
> > % in the x and y vectors with a delay of delayS seconds between each point.
> >
> > if ~isequal(numel(x), numel(y))
> > ? ? error('comet2:invalidCoords', 'The x and y inputs must have the same
> > number of elements.');
> > end
> >
> > if ~isreal(delayS) || delayS <= 0 || ~isscalar(delayS) || ~isfinite(delayS)
> > ? ? error('comet2:invalidDelayS', 'The delay must be a real finite positive
> > scalar.');
> > end
> >
> > h = line(NaN, NaN);
> > axis([min(x) max(x) min(y) max(y)])
> > set(h, 'UserData', 1);
> >
> > t = timer('TasksToExecute', numel(x), ...
> > ? ? 'ExecutionMode', 'fixedRate', ...
> > ? ? 'StartDelay', 0, ...
> > ? ? 'Period', delayS);
> > set(t, 'TimerFcn', @(varargin) updatePlot(h, x, y, t), ...
> > ? ? 'StopFcn', @(varargin) delete(t));
> > start(t);
> >
> > function updatePlot(h, x, y, t)
> > try
> > ? ? nextPoint = get(h, 'UserData');
> > ? ? set(h, 'XData', x(1:nextPoint), 'YData', y(1:nextPoint), 'UserData',
> > nextPoint+1);
> > catch %#ok<CTCH>
> > ? ? stop(t);
> > end
> >
> > --
> > Steve Lord
> > sl...@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ:http://matlabwiki.mathworks.com/MATLAB_FAQ

Hi

Could you please share what you have found so far? I am also trying to call some function via timer functions and in the background, but my GUI keeps getting locked for the time the m-file is running.

Best regards

Subject: Running a function in the background

From: Peder Schmedling

Date: 3 Mar, 2010 09:00:22

Message: 10 of 10

swgillan <swgillan@gmail.com> wrote in message <43fc2ee2-059a-4a4f-8455-1adf0388a02d@w37g2000prg.googlegroups.com>...
> Thanks for sharing that, I have never used a lot of the gcf stuff, so
> I will look over that code and take what I can from it. I was also
> passed on the watch_malloc code from the presenter, so I should be
> able to figure out how things were done!
>
> Thanks for all the help.
>

For those of you who also goes searching for the watchMalloc.m source code (like me), you'll be pleased to know that Michael Agostini (the presenter of Large Datasets in MATLAB) has uploaded it to file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/25579-watch-memory-allocation

The webinar in question:
http://www.mathworks.com/company/events/webinars/wbnr33692.html

best regards
Peder Schmedling

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
large datasets Peder Schmedling 3 Mar, 2010 04:04:10
timer Peder Schmedling 3 Mar, 2010 04:04:10
memory Peder Schmedling 3 Mar, 2010 04:04:10
watch_malloc Peder Schmedling 3 Mar, 2010 04:04:10
watch Peder Schmedling 3 Mar, 2010 04:04:10
watchmalloc Peder Schmedling 3 Mar, 2010 04:04:10
run Sprinceana 27 Sep, 2009 09:44:02
function Sprinceana 27 Sep, 2009 09:43:59
run a function Sprinceana 27 Sep, 2009 09:43:59
rssFeed for this Thread

Contact us at files@mathworks.com