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
引用格式
Stefan Schuberth (2024). tracer (https://www.mathworks.com/matlabcentral/fileexchange/122292-tracer), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
创建方式
R2022b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |