Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Running a function in the background
Date: Wed, 30 Sep 2009 10:04:09 -0400
Organization: The MathWorks, Inc.
Lines: 55
Message-ID: <h9vog1$4sb$1@fred.mathworks.com>
References: <f48e68c5-54f4-41b8-9843-0d8c995366b0@i4g2000prm.googlegroups.com> <h9qgfl$a89$1@fred.mathworks.com> <105ea682-707d-4779-b613-cd1c8bb7cfe0@e4g2000prn.googlegroups.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1254319425 5003 172.31.44.65 (30 Sep 2009 14:03:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 30 Sep 2009 14:03:45 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:573965



"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