122 this.List=
struct(
" Key ",[],
" Value ",[]);
130 function
set(
char key,any value) {
131 this.set_(key, value);
143 function value =
get(
char key) {
144 value = this.get_(key);
159 for i=1:length(this.List)
160 if strcmp(this.List(i).Key,key)
165 this.List(cidx) = [];
168 this.List=
struct(
" Key ",[],
" Value ",[]);
183 if ~isa(key,
" char ")
184 error(
" Key must be a string. ");
187 for i=1:length(this.List)
188 if strcmp(this.List(i).Key,key)
204 if (isequal(key(1).type,
" () "))
205 varargout[1] = this.get_(key(1).subs[1]);
210 [
varargout[1:nargout]] = builtin(
" subsref ",
this, key);
224 if (isequal(key(1).type,
" () "))
226 value = builtin(
" subsasgn ", this.get_(key(1).subs[1]), key(2:end), value);
228 this.set_(key(1).subs[1], value);
230 builtin(
" subsasgn ",
this, key, value);
244 #if 0 //mtoc++: 'get.Count'
245 function c =
Count() {
246 c = length(this.List);
253 #if 0 //mtoc++: 'get.Keys'
254 function k =
Keys() {
255 k = [this.List(:).Key];
262 #if 0 //mtoc++: 'get.Values'
264 k = [this.List(:).Value];
271 fprintf(
" Dictionary with %d elements.\n ",this.
Count);
272 arrayfun(@(kv)(
disp([
" Key: " kv.Key
" Value: " kv.Value])),
this.List);
283 function value = get_(key) {
288 if isa(key, "
char ")
289 for i=1:length(this.List)
290 if isequal(this.List(i).Key,key)
292 value = this.List(i).Value;
298 if key < 1 || key > this.
Count
299 error(" Key index exceeds dictionary. ");
301 value = this.List(key).Value;
304 error(" The key must be a
string or
integer ");
314 function set_(key,value) {
315 if isa(key,
" char ")
316 for i=1:length(this.List)
317 if isequal(this.List(i).Key,key)
319 this.List(i).Value = value;
324 this.List(end+1).Key = key;
325 this.List(end).Value = value;
327 if key < 1 || key > this.
Count
328 error(" Setting per numerical index only allowed within existing items; use a
char key for automatic insertions. ");
330 this.List(key).Value = value;
function this = subsasgn(key, value)
Implements subscripted assignment.
function set(char key,any value)
Sets the dictionary entry for key key to value value The keys are unique, so if a key already exists ...
cell Keys
The keys used in the dictionary. Readonly.
function clear(key)
Clears the dictionary or the contents for a specific key, if given.
A MatLab cell array or matrix.
Dictionary()
Creates a new empty dictionary.
integer Count
The size of the dictionary. Readonly.
Matlab's base handle class (documentation generation substitute)
A basic dictionary of key/value pairs for small to medium amounts of data.
disp
Handle object disp method which is called by the display method. See the MATLAB disp function...
cell Values
The values used in the dictionary. Readonly.
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
function display()
Overrides the default display method in MatLab and prints a list of keys and values inside the dictio...
function varargout = subsref(key)
Implements subscripted value retrieval.
A MatLab character array.
function bool = containsKey(char key)
Checks if the dictionary contains the key key.
A variable number of output arguments.