MATLAB Answers

OK
0

How to close .m script file in GUI with a push button?

Asked by OK
on 19 Aug 2019
Latest activity Commented on by OK
on 20 Aug 2019
How to close .m script file in GUI with a push button?

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 20 Aug 2019
Edited by Walter Roberson
on 20 Aug 2019
 Accepted Answer

allEditors = matlab.desktop.editor.getAll;
Now match the filename you want to close against {allEditors.Filename} to figure out the index of the session you want to close. For example,
filenames = regexp({allEditors.Filename}, '[^/\\]+$', 'match','once');
[found, idx] = ismember(FilenameToClose, filenames);
if found
allEditors(idx).close();
end
Except that you need to be more careful than this because there can be multiple files with the same last part of the file name, distinguished by directory.

  1 Comment

Nice, it worked well. Thanks!

Sign in to comment.