Info
この質問は閉じられています。 編集または回答するには再度開いてください。
running a script in a function
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
Guillaume
2015 年 1 月 22 日
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 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!