Matlab is often used in conjunction with other applications. The Modelit Directory Watcher provides an easy and flexible mechanism to activate and feed data to Matlab from external applications. The Modelit Directory Watcher runs in a parallel thread and does not block the Matlab code execution. A Matlab callback function is called each time the contents of a pre-specified directory change. The callback is invoked with an event object that contains information if a file has been added, deleted or modified. To avoid unnecessary callback triggers it is possible to set a filter on the directory to restrict the filetypes that need to be monitored.

MATLAB CODE EXAMPLE:

function main
%Example of usage of directory watcher
%specify exchange directory
wdir=fullfile(pwd,'extern2Matlab');
if ~exist(wdir,'file')
    mkdir(pwd,'extern2Matlab');
end
DWG=dirWatcher('directory',wdir,'callb',{@xmlRespond});
start(DWG);

%directory watcher remains active untill figure is killed
figure('deletef',{@stopDirWatcher,DWG})

function xmlRespond(obj,event)
disp(sprintf('filename    = %s',get(event,'file')));
disp(sprintf('action      = %s',get(event,'type')));

function stopDirWatcher(obj,event,DWG)
%Stop and clear directory watcher
stop(DWG);
clear('DWG');