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

Olympic puzzle number one

Asked by Jan Simon on 31 Jul 2012

Daniel has provided this nice puzzler:

```clear = @()disp('Have fun undoing this (:');
```

Let's solve this challenge and restore the original clear command in as many ways as you find.

John Petersen on 31 Jul 2012

Would somebody please answer this so I can use clear again? aaaah... Thanks Mike!!

Daniel on 31 Jul 2012

Credit should really be given to Loren.

Jan Simon on 31 Jul 2012

Yes, extra credits for Loren. Extra point for Daniel for the link to Loren's blog!

Products

No products are associated with this question.

Answer by Sean de Wolski on 31 Jul 2012
```system('matlab &');quit
```

1 Comment

Jan Simon on 31 Jul 2012

The rebirth method! +1 from Heidelberg!

On stage deeper: WinPower('rebootmatlab', 'which clear -all') I've always known that this tool will be useful for anything sometimes.

Answer by Mike Hosea on 31 Jul 2012
Edited by Mike Hosea on 31 Jul 2012
1. builtin('clear','clear')
2. You can delete the variable from the workspace window (highlight and press delete or right click and delete).

I look forward to reading some more creative ways.

Jan Simon on 31 Jul 2012

First! Thanks for taking the builtin out of the race. The workspace browser is an almost external tool to operate in the workspace. +1

Daniel on 1 Aug 2012

I wonder if the workspace window method method can be accessed by a java method from the commandline.

Answer by Sean de Wolski on 31 Jul 2012
```clear = rand(1000,500,700);
pack
```

Daniel on 31 Jul 2012

I like this solution.

Jan Simon on 31 Jul 2012

Relief by much beef. The weight-lifting method.

Answer by Daniel on 31 Jul 2012

Missing from the obvious solutions are:

```clear = str2func('clear'); clear();
```

and

```feval('clear');
```

Sean de Wolski on 31 Jul 2012

Nice! I would've thought the str2func solution would have recursively called itself.

Jan Simon on 31 Jul 2012

Re-identification using str2func is fine. I'm surprised that feval does not fail. Most of all: The first approach contains "clear" three times. This is the winner in synchronized swimming.

Mike Hosea on 1 Aug 2012

If you wanted to leave the rest of the workspace undisturbed it would have been four mentions of "clear":

clear = str2func('clear'); clear('clear');

Answer by Daniel on 31 Jul 2012

Somewhat surprisingly the CLEARVARS function is not a solution and gives an unhelpful error message. I think the failure probably qualifies as a bug.

Sean de Wolski on 31 Jul 2012

clearvars is just a fancy wrapper for evalin with clear.

```edit clearvars
```
Jan Simon on 31 Jul 2012

Disqualified. Who cares, the most important thing is not to win but to take part!

Daniel on 1 Aug 2012

@Sean, my point was that it could be a slightly fancy wrapper that could catch this error