Cannot clear classes in MATLAB 2013 without closing the session

6 visualizzazioni (ultimi 30 giorni)
I started a project in MATLAB R2010a at the beginning of the year and worked with classes and objects in MATLAB. I discovered a little later that classes are unable to be cleared unless the MATLAB session is closed and reopened. I came upon various questions and answers on the Mathworks questions page:
As for as I could understand, it was reported as a bug and was fixed in MATLAB R2013b. I have thus recently decided to move over to MATLAB R2013b which is available with a license. However, when working in MATLAB 2013, I still came upon the following warnings when trying to clear classes with the clear command:
Warning: Objects of '...' class exist. Cannot
clear this class or any of its superclasses.
> In Main at 27
Warning: Objects of '...' class exist. Cannot
clear this class or any of its superclasses.
> In Main at 27
...
...
Why are these warnings still happening? At the time of running my script called 'Main.m' where the objects are created, all possible windows that use the object (such as any Simulink models) are closed. The only open dialog is Main.m and the command window.
Is it perhaps because the classes that I wrote was written and saved in MATLAB R2010b?
MATLAB R2013b version:
---------------------------------------------------------------------------------------------
MATLAB Version: 8.2.0.701 (R2013b)
MATLAB License Number: 917548
Operating System: Microsoft Windows 7 Version 6.1 (Build 7600)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) Client VM mixed mode
---------------------------------------------------------------------------------------------
Example of my class definition:
classdef myClassName < handle
properties
...
end
methods
function obj = myClassName() % Constructor
...
end
end
end
  4 Commenti
Evert Trollip
Evert Trollip il 28 Nov 2014
Yes, I do call clear classes in this script, but only this script. I use Main to initialise all necessary objects. Open dialogs do not include figures, these are all closed.
I'll give a better example of what I am doing: I have a class named Aircraft which contains different properties that describe an aircraft. From this class I create two objects: Aircraft1 and Aircraft2. This is done in my Main script:
Aircraft1 = Aircraft();
Aircraft2 = Aircraft();
Everytime I make a change in the Aircraft class (for example, by changing one of the method functions) I need to clear the class and recreate the object. Otherwise, MATLAB gives a warning stating that the 'Aircraft' class has changed and might not behave as expected.
Matt J
Matt J il 28 Nov 2014
You can ignore the warning if you're merely changing the content of a method and not its calling syntax.
I recommend you attach a classdef file that will reproduce the issue. If it can't be reproduced with a simple example, we're probably not going to be able to guess the cause here.

Accedi per commentare.

Risposte (1)

per isakson
per isakson il 27 Nov 2014
Modificato: per isakson il 28 Nov 2014
I'm still using R2013a. I encounter this annoying "issue"
  • Since R2008a
  • When there is still a reference somewhere to some object. I've forgotten to delete a timer or something. That's expected behavior.
  • Often during debugging for no obvious reason.
  • IIRC, never during production runs.
Bugs have been reported and bugs have been fixed over the years, but the "issue" persists.
&nbsp
The release notes of R2014b gave me hope the "issue" is finally history, see Automatic Updates for Modified Classes
[...] MATLAB allows only one definition for a class to exist at any
time. Therefore, all existing objects of a class are updated
automatically to conform to the new class definition. You do not need
to call clear classes to remove existing objects when changing their
defining class.
  2 Commenti
Image Analyst
Image Analyst il 27 Nov 2014
In case anyone wants to know how to stop all timers:
function StopTimer(handles)
try
fprintf('Entering StopTimer...\n');
listOfTimers = timerfindall % List all timers, just for info.
% Get handle to the one timer that we should have.
if isempty(listOfTimers)
% Exit if there is no timer to turn off.
fprintf('There are no timers to turn off. Leaving StopTimer().\n');
return;
end
% Delete all timers from memory.
listOfTimers = timerfindall
if ~isempty(listOfTimers)
delete(listOfTimers(:));
end
fprintf('Left StopTimer and turned off all timers.\n');
catch ME
errorMessage = sprintf('Error in StopTimer().\nThe error reported by MATLAB is:\n\n%s', ME.message);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
return; % from btnStopTimer_Callback
Adam
Adam il 29 Nov 2014
I can confirm I have seen the automatic updating of classes in action in R2014b. I hadn't read about it in the release notes so it took me quite by surprise when properties I was adding to a class suddenly turned up in an object I currently had created in the main workspace.
I haven't looked into it in any depth, but I have noticed I have not had any of the annoying problems like those described that I used to have regularly in previous versions.

Accedi per commentare.

Categorie

Scopri di più su Methods in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by