Creating a Utility to Close All MATLAB Base Functions Open in the Editor
When your MATLAB code encounters an error and you have “dbstop if error” enabled, the file in which the error occurs is opened in the editor (together with its calling files). When the error occurs inside MATLAB base functions, located in the MATLAB installation directory, they too will open in the editor. It is convenient that this happens and assists debugging, but over time this can result in an accumulation of open files that can clutter your editor. Here, I write a utility that clears out these files. I use the function matlabroot to determine the MATLAB installation folder.
This video uses the code-along style.
Play the video in full screen mode for a better viewing experience.
Function is here:
function closematlabrootfiles
% Close files under matlabroot that are open in the editor
%% Get Files
allOpenFiles = matlab.desktop.editor.getAll'; % Array of open files
fileNames = {allOpenFiles.Filename}'; % Extract file names
%% Find Files Under MATLAB Root
foundCell = strfind(fileNames,matlabroot);
found = cellfun(@(x) ~isempty(x), foundCell); % Logical array for matlabroot files
%% Close Files
% Call close method of all matlabroot files
allOpenFiles(found).close
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。