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
  • 10,905
  • 5
  • 18
  • 32
Vivek Vardhan
  • 1,068
  • 3
  • 18
  • 42

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,091
  • 3
  • 21
  • 32