Loren on the Art of MATLAB

Turn ideas into MATLAB

Note

Loren on the Art of MATLAB has been archived and will not be updated.

Clearing the Air in Your MATLAB Session

I have, over time, changed when, where, and how I "clean up" my MATLAB session. You may want to update your strategy as well.

Contents

What I Used to Do

In the recent past, if I wanted to "start from scratch" without restarting MATLAB, I would clear my workspace, command window, and close open figures. I would issue the following commands

         clc
         clear all
         close all force

What I Do Now

I still do something very similar, but with an important though small-looking change. I remove the all from my clear statement. Here's what I do now.

         clc
         clear
         close all force

I no longer ask for everything to be cleared. Why not? Because it is overkill, and I am potentially clearing out things I would prefer to keep. Such as?, you might say. See this table, also copied here, to see the items.

You'll notice that the old clear all clears out much more than just variables in my workspace. In particular, it clears out functions and MEX functions that I've already run. There is no good reason to clear these out. In fact, you pay a price (perhaps small, perhaps not so small) when you run a function for the first time, since MATLAB needs to find the function (assuming it's MATLAB or MEX code) on a disk in a location on your MATLAB path, read it in, and prepare it so it can run (e.g., parse). Once MATLAB processes the file once, it does not need to do so again as long as the code remains in your session.

How Do I Run the Code?

Actually, instead of typing 3 lines, or even creating a code file, I use a MATLAB shortcut on my Quick Access toolbar. Here's what my entry looks like.

You'll notice that I use "ccc" as the tooltip for when my mouse hovers over the label. And the label itself is "X".

What Do You Do?

What do you do when you want to reset your MATLAB session? Start over? Reset the random number generator? I'd love to know your thoughts here.




Published with MATLAB® R2016a


  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。