MATLAB Answers


How to use clearvars in matlab6.5

Asked by Mekala balaji on 21 Dec 2017
Latest activity Commented on by Walter Roberson
on 22 Dec 2017
Accepted Answer by Jan
I want to remove all variables from command history except specified variables in Matlab 6p5, but I use: clearvars -except D F
But it gives an error, please someone help how to use this? or which function is equal to?


Also, if there isn't a good reason to stick to a 15 year old release, I would recommend updating to a newer release. Some of my functions have a 70% run time reduction even between R2012b and R2017b.
Matlab 6.5 is damn fast.
  • Time from double click on the desktop icon until Matlab's desktop is ready to use:
Matlab 6.5: 1.5 sec
Matlab 2016b: 17 sec
  • First opening of a medium size GUI containing 76 UICONTROLs, 2 small images and an empty axes (programmatic creation, not GUIDE):
Matlab 6.5: 2.0 sec
Matlab 2016b: 10.2 sec
  • For subsequent starts of the GUI, the processing is much faster:
Matlab 6.5: 0.3 sec
Matlab 2016b: 0.8 sec
  • A 3D animation (20 lines, 10 arrows, 20 small spheres, 2 squares which are semi-transpaent under OpenGL, background, a time counter as UICONTROL) in a self test using all different renderers:
Matlab 6.5: 29 sec
Matlab 2016b: 63 sec
NOTE: This Matlab 6.5 runs in a virtual XP machine with 1 core, while R2016b uses a real machine with 2 cores and accelerated hardware OpenGL drivers.
Some of the numerical computations are a little bit faster due to multi-threading and modern MKL versions. But as soon as any graphics are used, the Java methods do not have any chance to compete with the direct usage of the graphic system of the operating system.
For a typical work process, I use Matlab to discuss a clinical measurement with a patient or physician. Therefore I open Matlab and start the GUI. Total time: 3.5 sec compared to 27 sec. Imagine the emotion of the person sitting in front of me, remember the golden rule: Every computing process, which takes longer then 5 sec, causes mental stress.
But of course I do not develop code in version 6.5! Never ever. MLint is extremely valuable. Who cares about 23 seconds startup time, when the modern version avoids weeks of debug time?! I insist on using catch with the MException object, therefore the current versions of my codes do not run under 6.5 anymore. But when I have a task, which needs a lot of time for graphical outputs (create PDF sheets with 3 pages a 12 diagrams, legends, statistics and some markers) for 1200 patients, I will definitely do this under 6.5, except I want to let it run over night.
6.5 was a lean and rock hard system. Modern Matlab's are much more marshmallowig: more fluff, more sweets, more ribbons, more energy, more threads. It was a good time with v6.5 on XP, but now we have almost 2018 - not the right decade to work with rock hand ax.
@Rik: You cannot extrapolate the acceleration between 2012b and 2017b to older versions. But your suggestion is correct: It is time for an update.
@Jan thank you, you've opened my eyes. I'll keep it in mind for when I need to batch create graphical output. I have only started using Matlab from R2011b, so from there I have only seen speed increases (not caring about boot up time).

Sign in to comment.

1 Answer

Answer by Jan
on 21 Dec 2017
 Accepted Answer

It is a bad programming practice to control the existence of variables by clear. Better use functions to keep the workspaces clean. But if you really want to do this: Search in the FileExchange for some submissions, which work with historical Matlab versions also:


Show 1 older comment
Sir, but any other way to remove variables from workspace except specified variables?
See the link Jan posted.
And to be clear: in R6.5, there was no built-in way to clear everything except some variables.

Sign in to comment.