Octave 4.2 from Ubuntu 18.04 doesn’t yet support clearvars, so you’ll have to do without it. A simple “clear” command will most likely do the same for your purpose. I know some tutorials use clearvars at the beginning of sample code, instead of the clear command, which is well supported everywhere, not only on recent Matlab.
But as a general approach, if you only have a single display machine, add the PsychDebugWindowConfiguration; command at the top of your script during development. This will give you a half transparent window, so you can see the Octave command window output with error messages etc. so you don’t get confused if things freeze or such, because your script aborted with some error, or simply finished after showing a purple background in your case. Makes debugging easier. Then you can compare what you write against tutorials if something goes wrong.