Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

running a script in a function

2 visualizzazioni (ultimi 30 giorni)
AA
AA il 22 Gen 2015
Chiuso: MATLAB Answer Bot il 20 Ago 2021
fsw = System.IO.FileSystemWatcher();
fsw.Path = 'C:\Users\wolfgang';
fsw.Filter = 'test.csv';
fsw.EnableRaisingEvents = true;
listenerhandle = addlistener(fsw, 'Changed', @(~,~)testing1234(q,a));
%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
I have saved the above code as the function systemwatch.
When I type in systemwatch manually in the command window then it gets executed without trouble. However, when I run this script systemwatch in another function then it does not get executed somehow. Can anyone explain this and tell me how to fix this please??
function if
if rowsOfMaxes<3 || rowsOfmin<3
systemwatch;
end
end
Basically, before i start the function, there is already an active listenerhandle and systemwatch running. The function has a condition and if the condition is met then I want certain parameters of the listenerhandle or systemwatch file to change.
I want this line
listenerhandle = addlistener(fsw, 'Changed', @(~,~)testing123(q,a));
to change to this
listenerhandle = addlistener(fsw, 'Changed', @(~,~)testing1234(q,a));
and I want this line
fsw.Filter = 'coke.csv';
to change to this
fsw.Filter = 'test.csv';
thanks

Risposte (1)

Guillaume
Guillaume il 22 Gen 2015
I would create the listener before enabling the FileSystemWatcher events.
Is this the exact code that is in the file systemwatch.m? Without any function prototype? If that is the case, then systemwatch.m is a script not a function. Possibly it doesn't work in a function because the listenerhandle goes out of scope.
Also shouldn't the code for listenerhandle be:
listenerhandle = addlistener(fsw, 'Changed', @(q,a) testing1234(q,a));
  1 Commento
AA
AA il 22 Gen 2015
so how can i resolve this problem?

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by