How do I pause Matlab execution to wait for file edits
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am trying to open and edit a file within a Matlab function and pause Matlab execution until the file is closed. However, the code I have implemented takes a very long time to return when the file being editied is closed by the user. My code is listed below:
function [x] = DoSomething(u)
ef = matlab.desktop.editor.openDocument(fullfile(pwd,'Inputs.m')); % opens the file in the editor
waitfor(ef,'Opened',0); % this line waits for the editor property 'Opened' to change from a 1 to a 0 when the file is closed
x = u;
return
This coding works within the function however the waitfor takes a very long time to detect that the file was closed in the editor and then allow Matlab to continue computations within the m-file. The time to detect closing can vary up to several minutes.
0 Kommentare
Antworten (1)
Jan
am 19 Apr. 2019
It is a bad idea to edit M-files during the execution. It would be much better to edit a file, which contains the modified parameters only. Using a standard GUI to modify the parameters is smarter also, than using Matlab's editor as GUI.
You could use a listener to check for changed files:
w = System.IO.FileSystemWatcher(pwd);
w.Filter = 'Input.m';
w.NotifyFilter = System.IO.NotifyFilters.LastWrite;
addlistener(w, 'Changed', @changedFcn);
w.EnableRaisingEvents = true;
Now you have to implement the resuming in the changedFcn. But I think this is too indirect. Use a standard GUI instead to modify the parameters and leave the M-files untouched.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!