I am working on a statistical model of a content distribution server in MATLAB and have decided to use OO programming. This is my first foray into OO with MATLAB and I have hit a snag. I am attempting to model a download connection to the server, at the moment it is just a MATLAB timer and a boolean. When the timer expires I want to set the isActive field from true to false. So quite simple I feel but then I have been battling with this for more then a day now. Below is the code for the class so far:
classdef dl<handle
properties
isActive = true
ttl = 0
end
methods
function this = startTimer(this, varargin)
this.ttl = timer('TimerFcn', @()killConnection(this), 'StartDelay',1);
start(this.ttl);
end
end
methods (Access = private)
function obj = killConnection(obj, varargin)
obj.isActive = false;
end
end
end
I solved the problem I was having, the issue was in the way the callback handler was declared. Im not sure if the precise reason but there is a better explanation here if anyone is interested, see this blog post http://syncor.blogspot.com/2011/01/matlabusing-callbacks-in-classdef.html.
Here are the changes I made to get successful operation. Firstly i changed the callback function into the proper structure for the callback:
Then I declared the callback differently in the timer:
This worked for me. Thanks for the help it was really getting to me :P.