The problem comes when I am trying to use MATLAB handle objects as key values in MATLAB containers.Map.
ld( h1, h2 )
defines a linear order on handle objects, so there should be no limitation on using handle objects as key values for maps, however only integer or string types are allowed.
A workaround for this problem could be retrieving the actual ids (addresses) of handle objects (which are basically being compared in ld
function).
So the question is: how to get the ID of a handle object?
Found out that a workaround can be done using persistent variables in static member functions.
In this case you should inherit all your classes from a base class like the following.
classdef object < handle
properties ( GetAccess = 'public', SetAccess = 'private' )
id
end
methods ( Access = 'protected' )
function obj = object()
obj.id = object.increment();
end
end
methods ( Static, Access = 'private' )
function result = increment()
persistent stamp;
if isempty( stamp )
stamp = 0;
end
stamp = stamp + uint32(1);
result = stamp;
end
end
end