the handle class tracer impements the possibility to monitor the programm flow inside a class.
Just inherit the class to your testclass like:
classdef testclass < tracer
The methods:
AddTrace adds the actual stack of the method call to the property trace.
IsInternalCall checks if the method call is from within the class or from the command line / other class
ListTrace show the trace in detail what methods have been called.
This can be very usefull if you just want the get/set method to do special stuff when it is called from the command line, or when it is called internally.
EXAMPLE:
I used it to control a heating element.
a=heater; a.temperature=40; communicates with RS232 and sets a new temperature
during heating up obj.temperature=actual_temperature; just sets a new temperature to the properties inside the class
classdef testclass < handle & tracer
properties
g=[1 2 3 4 5];
end
methods
function set.g(obj,x)
%obj.AddTrace;
disp('set g');
obj.g=x;
disp(sprintf('internal call: %i',obj.IsInternalCall));
end
function b=get.g(obj)
%obj.AddTrace;
disp('get g');
b=obj.g;
disp(sprintf('internal call: %i',obj.IsInternalCall));
end
function aa(obj)
obj.ListTrace;
end
function bb(obj)
%obj.AddTrace;
obj.g=3;
end
function c=cc(obj)
%obj.AddTrace;
c=obj.g;
end
function ListTrace(obj)
disp(obj.trace);
disp(sprintf('internal call: %i',obj.IsInternalCall));
end
end
end
Zitieren als
Stefan Schuberth (2024). tracer (https://www.mathworks.com/matlabcentral/fileexchange/122292-tracer), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2022b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0 |