我想要一个类似于 Matlab 的 OOP 接口,在某种程度上我有类似的东西
classdef Foo
properties (Constant)
dict = NaN;
end
methods (Static)
function list = search(varargin)
%...
Foo.dict = cell(10,5); % etc..
end
end
end
所以我可以访问和修改(静态)属性。我应该如何设置它?不是Constant
我猜..
更新:我的问题是t9.load();
不更新t9.dict
classdef t9
%T9 Summary of this class goes here
% Detailed explanation goes here
properties% (Static)
dict = {};
end
methods (Static)
function load()
load('usdict.mat');
t9.dict = usdict;
end
function matches = search(varargin)
matches = {};
num_words = nargin-1;
for word=t9.dict(num_words, :)
if strcmp(word,'')
continue;
end
word_cell = word{1};
success = true;
for i=1:num_words
char = word_cell(i);
if ~ismember(char, varargin{i})
success = false;
end
end
if success, matches{end+1} = word_cell; end
end
end
end
end
愿望:
t9.load();
t9.search('ABC', 'DEF');
t9.search('DEF', 'GHI', 'MNO');