i design a GUI.... and inside a button i give "clear all" to clear all variables as it takes lots of space... but the gui design tables and static text and axes and all the other design items also gets cleared.... how to clear only variables without clearing the gui design....

1 Kommentar

Why don't you just clear your variables by listing them after clear, like
clear var1 var2

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 5 Mai 2014

1 Stimme

Elysi - if there are specific variables that you want cleared, then you can clear them by name:
x = zeros(100,100);
y = zeros(1000,33);
z = ones(32,32);
% do some stuff
% clear just x and y only
clear x y;
Type help clear from at the command window for more details.

4 Kommentare

Elysi Cochin
Elysi Cochin am 6 Mai 2014
i have lots of variables... i wanted to clear all the variables when i execute it the second time.... but the gui controls also gets cleared... how to delete only variables without deleting the gui controls....
Geoff Hayes
Geoff Hayes am 6 Mai 2014
The clear command has the following option (type help clear for details):
clear -REGEXP PAT1 PAT2 can be used to match all patterns using regular expressions. This option only clears variables. For more information on using regular expressions, type "doc regexp" at the command prompt.
So if you can somehow distinguish between your variables and the ones in the GUI, then you can use some sort of pattern to remove/clear the ones you want (or don't want).
Maybe this question should have already been asked, but what variables do you have that need clearing that don't get cleared automatically when a function is exited (no longer has scope)? Are you creating lots of global variables for use everywhere? Perhaps provide an example of how you are using variables that need to be cleared.
Elysi Cochin
Elysi Cochin am 7 Mai 2014
i still didnt get a solution.... how to keep the gui controls and delete all other variables...
Elysi - please provide a sample of your code that describes where all these variables are coming from i.e. those that you wish to clear, and your use of the clear all command. I still don't understand why you have so many variables that need to be cleared and why you are invoking the clear all command within your code.
Or, you can prefix all of your GUI controls with a gui_ prefix, and then execute the clear command on anything but those variables. For example, in the Command Window type:
clear all; % clear all existing variables and other
x=123; % create five different variables
y=zeros(12,12);
z=cell(1,34);
gui_text1=123.4;
gui_text2=345.3;
Now you can clear all but the gui_ variables with the following command:
clear -regexp ^(?!gui_)\w

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Variables finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by