The clc command clears all text from your MATLAB Command Window
To clear the Command Window in MATLAB, type clc at the prompt and press Enter. This removes all previous commands and output from view, giving you a blank workspace to work in. The command does not delete any variables or functions you have created — it only erases what appears on screen.
The clc command works the same way in every version of MATLAB and takes effect immediately. You can run it as many times as you need during a session without affecting your work.
Key Takeaways
- Type clc and press Enter to clear the Command Window display without losing any variables or functions.
- The clc command only removes text from the screen — your workspace data remains intact and usable.
- You can clear the Command Window from within a script or function by including clc on its own line.
- If you need to clear both the display and your variables, use clear to remove variables and clc to clear the screen.
Using clc in scripts and functions
When you include clc in a script or function file, it clears the Command Window each time that script or function runs. This is useful when you want a clean display before showing results to the user. Place clc at the beginning of your script if you want the window cleared before any output appears.
For example, a script that performs calculations and displays results might start with clc so that old output from previous runs does not clutter the display. When someone runs your script, they see only the current results.
Clearing the Command Window versus clearing variables
MATLAB has two separate commands that do different things. The clc command clears only the display — the text you see on screen. The clear command removes variables from your workspace. You can use both in the same script if you need to do both tasks.
If you type clear alone, it removes all variables. If you type clear variablename, it removes only that specific variable. Neither of these commands affects what appears in the Command Window. To remove both the display and your variables, run clear first, then clc.
Keyboard shortcuts as an alternative
On Windows and Linux, you can press Ctrl+L to clear the Command Window without typing the clc command. On Mac, the equivalent shortcut is Command+L. These keyboard shortcuts perform the same action as typing clc — they clear the display but leave your variables and functions in place.
The keyboard shortcut is faster if you clear the window frequently during interactive work. The clc command is more useful in scripts because it is explicit and works the same way regardless of your operating system or keyboard layout.
What clc does not do
The clc command does not close any open figures or plots. If you have created graphs or images in separate figure windows, they remain open after you clear the Command Window. To close those windows, use the close command or close them manually by clicking the X button.
The clc command also does not affect the Workspace browser, the Editor, or any other MATLAB window. It only affects the Command Window itself. If you want to see what variables still exist after clearing the display, look at the Workspace panel on the right side of the MATLAB interface.
Clearing the Command Window history
The clc command clears what you see on screen, but MATLAB still remembers your command history. You can scroll up in the Command Window or use the up arrow key to recall previous commands you typed, even after running clc. This history persists for the entire session unless you close MATLAB completely.
If you want to remove the command history as well, you can clear it through the Command History window. Right-click in the Command History panel and select Clear Command History. This action is separate from clc and is not something you typically need to do during normal work.
Frequently Asked Questions
Does clc delete my variables?
No. The clc command only clears the display in the Command Window. All variables, functions, and data in your workspace remain unchanged and ready to use. If you want to remove variables, use the clear command instead.
Can I clear the Command Window from within a function?
Yes. You can include clc on its own line anywhere in a function or script file. When that function runs, it will clear the Command Window at that point in the execution. This is often done at the start of a function to provide a clean display before output appears.
What is the difference between clc and clear all?
The clc command clears only the display. The clear all command removes all variables, functions, and breakpoints from your workspace. Using both together clears both the screen and your workspace, but they do separate things.
Why would I use clc in a script?
Using clc at the start of a script ensures that old output from previous runs does not appear on screen. This gives the user a clean view of only the current results. It is especially useful in scripts that other people will run.
Can I undo clc if I need to see previous output?
No, clc is permanent for the current session. However, you can scroll up in the Command Window to see some previous output if it is still in the buffer. For important output you need to keep, copy it to a text file or save it to a variable before clearing the window.