Clear all returns warning evaluatecode.m could not be cleared because it contains the code that is currently executing?

4 views (last 30 days)
I don't use clear all to clear workspace variables. I only use it at the beginning of the main method (that calls other functions) to make sure I have a fresh start after tests to make sure small parts of the algorithm works.
With that background out of the way, recently when I try to run a section that only contains a clear all; (first line of the whole code) and a clc;, it returns the following 3 warnings that I have never seen before (as I have been using clear all in this fashion for a long time):
Warning: The file 'C:\Program
Files\MATLAB\R2018a\toolbox\matlab\codetools\embeddedoutputs\+matlab\+internal\+editor\evaluateCode.p'
could not be cleared because it contains MATLAB code that is currently executing.
Warning: The file 'C:\Program
Files\MATLAB\R2018a\toolbox\matlab\codetools\embeddedoutputs\+matlab\+internal\+editor\evaluateCode.p'
could not be cleared because it contains MATLAB code that is currently executing.
Warning: The file 'C:\Program
Files\MATLAB\R2018a\toolbox\matlab\codetools\embeddedoutputs\+matlab\+internal\+editor\evaluateCode.p'
could not be cleared because it contains MATLAB code that is currently executing.
I am not as annoyed but interested in knowing why it suddenly starts to produce these warnings when it hadn't done so in the past 5 years of my experience with using clear all in MATLAB. It also produces other warnings such as when I try to load a data file it warns some subscripts are missing or something, which I turned the warning off after searching on google.

Accepted Answer

Jan
Jan on 26 Sep 2018
Edited: Jan on 26 Sep 2018
I don't use clear all to clear workspace variables.
I only use it at the beginning of the main method.
This is a contradiction. To "make sure I have a fresh start" simply use functions instead of scripts, and the problems will vanish immediately.
when I try to run a section
This might mean, that you stopped the code in the debugger and evaluate some lines of code manually. Then functions, which are currently processed, cannot be cleared, of course. If you do something else, please explain exactly, what it is.
It also produces other warnings such as when I try to load
a data file it warns some subscripts are missing or something
What or who is "it"? Please post the code and the complete text of the warning. "Or something" does not allow to understand the cause of the problem. Turning off warnings is a bad idea in general. Prefer to fix the cause of the problem instead.
  2 Comments
Zhangxi Feng
Zhangxi Feng on 26 Sep 2018
You mean even the main program you put it under a function? How do I check the workspace variables when some outputs look wrong but not sure which part(s) caused it then? Save the entire workspace variables everytime?
I don't remember the exact warning or how to proc it at this time. When I looked it up, the answer says it should be automatically suppressed but somehow isn't so it suggested to turn off the warning.
Stephen23
Stephen23 on 26 Sep 2018
Edited: Stephen23 on 26 Sep 2018
"How do I check the workspace variables when some outputs look wrong but not sure which part(s) caused it then? Save the entire workspace variables everytime?"
No, that is exactly what the debugging tools are for:
Programmers need to debug code, therefore programmers invent lots of tools to help them debug their code. Those are the tools that you should learn to use.
Beginners love scripts because they like to "see" all of their variables in the base workspace. And then they have to put clear everywhere, which is like shooting yourself in the foot just before running a race. Experienced programmers use functions because they like their code to work properly (and don't use clear).

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!