0

Does MATLAB keep some variables after clearing?

Matlab: Free memory is lost after calling a function

My question is related to this post but some changes are there.

I have to use the output (the outputs are matrices generated, i.e. i am generating small matrices in every iteration) produced by previous large program, in my next iteration of large program, so when i am using the technique mentioned in the post, i am getting error that " Reference to a cleared variable", i need to keep some of the variables and some matrices generated. How to do that?

Sometimes the error occurs after 1 iteration only

Thanks

braX
  • 11,506
  • 5
  • 20
  • 33
Vivek Vardhan
  • 1,118
  • 3
  • 21
  • 44
  • 1
    See [here](http://stackoverflow.com/questions/15565396/is-it-possible-to-have-a-workspace-variable-that-persists-across-a-call-to-clear) – HebeleHododo Apr 05 '13 at 06:01

1 Answers1

1

You can clear specific variables in the workspace with:

clear myvarname

You can also clear functions that might be holding persistent variables with:

clear myfunname

So - you should work out which ones you don't want (type whos to see variables in the workspace, or in a breakpoint) and clear the ones you don't need.

Another option would be to save the ones you do want, use the clear method you mentioned, then re-load.

pancake
  • 3,232
  • 3
  • 22
  • 35