Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
clear workspace--including array editors

Subject: clear workspace--including array editors

From: Bob

Date: 16 Oct, 2011 16:51:39

Message: 1 of 2

A few days ago I wrote about ways to close all open array editor
windows.
There does not seem to be a built in function to do this, so I wrote
one based
on some code I found on Loren's blog and suggestions from my last
post.

The code relies on the fact that the 'Window|Close All Documents'
command
closes the array editors but also all the files open in the editor.
So the function gets the names of the files, prompts the operator to
close all documents
and then re-opens the files.

I have tested it a few times and it works OK on my R2007b
One remaining problem is that Close All Documents does not close
object inspector windows.

OK, here is the code
---------------------------------
% clrg.m -- clear workspace variables, figures, and array editor
windows
% usage: clrg
% close all documents when prompted

   % get files open in editor
editorServices = com.mathworks.mlservices.MLEditorServices;
editorState = editorServices.builtinGetOpenDocumentNames();
fnames = cellstr( char( editorState ) );

   % get operator to close documents--
   % this closes array editors but also files in editor
   % will prompt for files where changes have not been saved
reply = input('Select Window|Close All Documents, then press enter ',
's');

   % reload the files that were open in the editor
if ~isempty(fnames)
   for k = 1:length(fnames)
      edit(fnames{k});
   end
end

close all
clear variables
clear fun

Subject: clear workspace--including array editors

From: Bob

Date: 18 Oct, 2011 16:38:25

Message: 2 of 2


bump


On Oct 16, 9:51 am, Bob <ralva...@spambob.net> wrote:
> A few days ago I wrote about ways to close all open  array editor
> windows.
> There does not seem to be a built in function to do this, so I wrote
> one based
> on some code I found on Loren's blog and suggestions from my last
> post.
>
> The code relies on the fact that the  'Window|Close All Documents'
> command
> closes the array editors but also all the files open in the editor.
> So the function gets the names of the files, prompts the operator to
> close all documents
> and then re-opens the files.
>
> I have tested it a few times and it works OK on my R2007b
> One remaining problem is that Close All Documents does not close
> object inspector windows.
>
> OK, here is the code
> ---------------------------------
> %clrg.m -- clear workspace variables, figures, and array editor
> windows
> %  usage:clrg
> %  close all documents when prompted
>
>    % get files open in editor
> editorServices = com.mathworks.mlservices.MLEditorServices;
> editorState = editorServices.builtinGetOpenDocumentNames();
> fnames = cellstr( char( editorState ) );
>
>    % get operator to close documents--
>    % this closes array editors but also files in editor
>    % will prompt for files where changes have not been saved
> reply = input('Select Window|Close All Documents,  then press enter ',
> 's');
>
>    % reload the files that were open in the editor
> if ~isempty(fnames)
>    for k = 1:length(fnames)
>       edit(fnames{k});
>    end
> end
>
> close all
> clear variables
> clear fun

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us