Stuart’s MATLAB Videos

Watch and Learn

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
|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.