0

I want to delete some variables that I have declared in command window in matlab, I tried clear all but it didn't work. I typed the following in the command window, e.g.

a = 10;
str = 'a';
clear all

Matlab doesn't delete them, why? Is there any function that can do this for me?

Buck Thorn
  • 5,024
  • 2
  • 17
  • 27
hj-007
  • 332
  • 3
  • 6
  • 16
  • 3
    `clear all` certainly deletes variables from the workspace (unless you've managed to redefine `clear`). Do you mean you want to empty the command window ? If so, try `clc`. – High Performance Mark Aug 30 '13 at 10:02
  • If you have managed to redefine clear, see http://stackoverflow.com/questions/18360624/how-to-remove-the-variable-clear-in-matlab for how to clear `clear` – am304 Aug 30 '13 at 10:06

3 Answers3

1

1) If you have redefined function clear (e.g. by a variable or function), you can use the builtin function to execute built-in clear function. I.e. you can use

builtin('clear','all')

to clear all variables, respectively

builtin('clear','clear')

to redefine clear to the built-in clear function and then use it normally

clear all

2) If this was not the solution of your problem, could you show us the output of the following code?

a = 10;
str = 'a';
builtin('clear','all')
builtin('who')
Milan
  • 492
  • 4
  • 12
1

To clear all of your variables in matlab you type:

clear

If you want to clear a specific variable, for instance "a" you tpye:

clear a

I suspect your problem is that you have named a variable "all" so when you use clear all you end up only clearing the variable all.

You should be careful about what names you are giving to your variables. You can useexist {variable} to check if the variable you want to assign is already used by a matlab function.

Ben
  • 93
  • 1
  • 7
1

use "Clear" only it will work or u want to remove particular variable the put variable name in last of " Clear Var_name"

Karthick
  • 11
  • 1