How to clear the former command
150 views (last 30 days)
Show older comments
Of course,we know the function clc will clear all input command.But sometimes,I just want to clear the former one command or former two,but not former all.Is this possible?
0 Comments
Answers (3)
Image Analyst
on 8 Jul 2017
" when I make some typo in the second command.I should re-type all command..So if I can delete previous one or two,it will make my life easier."
Learn how to write a script. You can't progress in MATLAB just doing everything from the command line all the time. Then, your "question" will no longer be a problem. Simply run your script again.
If you really want to remove something prior that you typed on the command line from the history, then type up arrow (to reveal the history) then, right click on the prior command that you want to remove from the history list, and select "Cut". It will no longer appear in the history. (I know, I just tried it and verified that.)
2 Comments
Jan
on 8 Jul 2017
+1: a) A script or function will be much better than collecting commands in the command window. b) the right click in the command history (not in the command window) works - but see a) for a better solution.
Image Analyst
on 9 Jul 2017
You can see the history as a popup window in the command window (like my Answer above), or in it's own docked history window. To clarify...
To view the command history, press the up-arrow key, ↑, in the Command Window. To retrieve a command using a partial match, type any part of the command at the prompt, and then press the up-arrow key. You can right click inside this popup history window nested inside the command window to delete the item from the history.
To dock or detach the Command History window, click , and then select an option. To view the Command History if it is closed: on the Home tab, in the Environment section, click Layout. Then, under Show, click Command History and select either Docked or Popup.
Hudson Hornet
on 15 Nov 2018
Edited: Hudson Hornet
on 14 Jan 2019
There is one interesting way. Go to Preferences > Command History.
You'll be able to set Save last X commands. If you set it to 10 and apply, it'll remove all except last 10 commands. Then you can set it back to default (25,000 with my release - 2018a) or anything you want.
Jan
on 8 Jul 2017
clc does not clear "the input", but the output to the command window. This might look nitpicking, but the difference might concern the question. Note that the output is not securely deleted, but it vanishes from the display in the command window only.
What is the purpose of removing one or two "commands" from the command window? You could try to do thisusing the methods included in FEX: CmdWinTool, see the comments in the "getText" method. Unfortunately all my trials ended with a crash. I stopped further investigations, because modifying the output to the command window is too awkward at all. The command window is not the correct locations for smart tricks. Therefore I suggest to think twice, if your aim can be achieve directly in a much cleaner way.
2 Comments
Steven Lord
on 8 Jul 2017
Edited: Steven Lord
on 8 Jul 2017
If you want to do this so you can simply copy and paste the output from the Command Window into a report or something like that, consider writing a script file (as others have suggested) or logging the Command Window output to a file using the command diary then prune the diary file to only include the output you want to report.
There's also the possibility of using the Live Editor, where the output will appear in the script file itself.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!