The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: "clear -except" and "clearvar -except"
Replies: 1   Last Post: Sep 24, 2013 11:38 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 11
Registered: 5/21/10
"clear -except" and "clearvar -except"
Posted: Sep 24, 2013 4:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi all, I would like to discus about the result of "clearvars -except" and "clear -except" with others.
When I tried to run a program in loop , I have to clear all variables, workspace etc except the running variable , which is used as the only one parameter ( input ), to continue to the next iteration. As the program is very lengthy , I herewith explain the situation with a simple loop.

In the following program I have to keep the value of the variable i . Herewith I give three variations of the program. But the when I try to keep the value of the variable i , matlab keep the value of the variable j and erases the variable i and viz versa. [Note that "clearvars -except" command works well as I expect. The only problem is "clearvars" clears only variables and not the entire workspace.

%% ----------------------------First version of the program---------------------------------------
for i=1:10
clearvars -except i % This line works as I expect

The output is :-
Name Size Bytes Class Attributes
i 1x1 8 double

%% ----------------------------Second version of the program---------------------------------------
for i=1:10
clear -except i % This line is NOT working as I expect.

The output is :-
Name Size Bytes Class Attributes
j 1x1 8 double
You may be appreciated if you run the above programs and give your suggestions

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.