Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

running a script in a function

2 views (last 30 days)
AA
AA on 22 Jan 2015
Closed: MATLAB Answer Bot on 20 Aug 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

Answers (1)

Guillaume
Guillaume on 22 Jan 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 Comment
AA
AA on 22 Jan 2015
so how can i resolve this problem?

This question is closed.

Community Treasure Hunt

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

Start Hunting!