classdef SingletonClass < handle methods(Access = private) function obj = SingletonClass() disp(‘SingletonClass construtor called!‘); end end methods(Static) function obj = getIns() persistent ins; if isempty(ins) || ~isvalid(ins) ins = SingletonClass(); end obj = ins; end end end
原文:https://www.cnblogs.com/usaddew/p/10846776.html