
How to clear variables in Octave
In this lesson I'll explain how to delete the variables from the Octave work area through a practical example.
What is the purpose of deleting variables? When you work with a lot of data (big data) you have to manage the computer memory to avoid running out of computer memory (overflow of memory). To avoid this problem you can periodically free the Octave workspace.
Create three variables
>> a=1;
>> b=2;
>> c=3;
To delete all the variables and their values from the Octave memory type the command clear
>> clear
This command deletes all variables from the workspace.
How to delete a single variable
If you want to clear just one variable, type the clear command followed by the variable name
>> clear a
How to delete a group of variables
If you want to delete only a group of variables you can use special characters ? and *
? = any single character
* = any zero or more characters
For example, if you want to delete all variables starting with the letter r and ending with the letter e, type clear ro*e
>> clear ro*e
In this way you delete the variables rome, rose, route, rotate, etc.
If you want to delete all the variables with a name of 4 characters starting with the letters ro and ending with the letter e, type clear ro?e
>> clear ro?e
In this way you delete the variables rome, rose, robe, etc.
How to delete global variables
To clear only global variables from the workspace add the option -g to the clear command
>> clear -g
How to delete functions
To clear only the functions from the memory area, add the option -f to the clear command
>> clear -f