automatic import into matlab after time period

2 Ansichten (letzte 30 Tage)
AA
AA am 17 Nov. 2014
Beantwortet: Guillaume am 17 Nov. 2014
I have .csv file on my desktop which get replaced every 49 minutes. Can i put a command in matlab which imports this file every 49 minutes into matlab for calculations?

Akzeptierte Antwort

Guillaume
Guillaume am 17 Nov. 2014
You can use a timer for that:
t = timer;
t.Period = 49 * 60;
t.TimerFcn = importfcn; %for you to define with signature: function importfcn(obj, event)
t.ExecutionMode = 'fixedRate';
Alternatively, on Windows, you could use .Net System.IO.FileSystemWatcher to raise an event whenever the file is modified
fsw = System.IO.FileSystemWatcher();
fsw.Path = 'somefolder';
fsw.Filter = 'filename.csv';
fsw.EnableRaisingEvents = true;
listenerhandle = addlistener(fsw, 'Changed', importfcn);
%signature of importfcn is function importfcn(sender, eventargs)
%add a small delay in importfcn before reading the file as the event is raised
%to make sure that file modification is complete

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by