复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16classdef 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
注:persistent变量不会随着.m文件运行结束而被清除,如果需要清除,可以有以下几种方法:
1、clear all
2、clear classes
3、clear SingletonClass
4、delete(SingletonClass.getIns())
最后
以上就是落后短靴最近收集整理的关于Matlab单例模式的全部内容,更多相关Matlab单例模式内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复