comparison Map.m @ 951:a6c5e73ff44e

Better errors in Map()
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Dec 2018 16:10:58 +0100
parents effd75b113ba
children
comparison
equal deleted inserted replaced
902:306f5b3cd7bc 951:a6c5e73ff44e
57 end 57 end
58 58
59 function v = subsref(obj, S) 59 function v = subsref(obj, S)
60 switch S(1).type 60 switch S(1).type
61 case '()' 61 case '()'
62 if length(S.subs) > 1
63 error('sbplib:Map:multipleKeys', 'Multiple dimensions are not supported. Use a cell array as a key instead.');
64 end
62 k = S.subs{1}; 65 k = S.subs{1};
63 try 66 try
64 v = get(obj, k); 67 v = get(obj, k);
65 catch ME 68 catch ME
66 if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey') 69 if strcmp(ME.identifier,'MATLAB:Containers:Map:NoKey')
79 end 82 end
80 83
81 function obj = subsasgn(obj, S, v); 84 function obj = subsasgn(obj, S, v);
82 switch S(1).type 85 switch S(1).type
83 case '()' 86 case '()'
87 if length(S.subs) > 1
88 error('sbplib:Map:multipleKeys', 'Multiple dimensions are not supported. Use a cell array as a key instead.');
89 end
84 k = S.subs{1}; 90 k = S.subs{1};
85 set(obj, k, v); 91 set(obj, k, v);
86 otherwise 92 otherwise
87 error('You can''t use dot notation because Matlab(TM). What is this piece of shit software anyway?') 93 error('You can''t use dot notation because Matlab(TM). What is this piece of shit software anyway?')
88 end 94 end