I am trying to use str2func
to call different methods of my class depending on a specific properties value (in this case obj.type
).
So, I have
classdef myClass
properties
type %# values are different file extensions (LSM, TIFF, OIF etc...)
end
methods(public)
function process(self)
%# here I would like to do something in the lines of
funHandle = str2func(['@()self.process_' self.type])
funHandle() %# E1
end
end
methods(private)
%# I have a bunch of methods named process_[type]
process_LSM(self)
process_TIF(self)
% etc...
end
end
However, this does not work. On line E1 (above) MATLAB complains that class self is undefined and Java might not be running? Is there away to get this to work or do I have to use a switch structure in method process to call the type specific methods process_[type]?
You need to use functional notation here, not dot notation. The following works: