1classdef myclass2 < handle 2 properties 3 data_ 4 end 5 6 methods 7 function obj = myclass2 () 8 obj.data_ = 1001:1005; 9 end 10 11 function r = subsref (obj, S) 12 switch (S(1).type) 13 case '.' 14 switch (S(1).subs) 15 case 'data' 16 % Transform: obj.data --> obj.data_ 17 r = obj.data_; 18 if (length (S) > 1) 19 r = subsref (r, S(2:end)); 20 end 21 case 'alldata' 22 % Transform: obj.data --> obj.data_(1:end) 23 % This statement should trigger *builtin* subsref *twice* (one 24 % for the evaluation of 'end', and the other for the whole rvalue). 25 % 'end' here is also builtin 'end' 26 r = obj.data_(1:end); 27 28 if (length (S) > 1) 29 r = subsref (r, S(2:end)); 30 end 31 otherwise 32 error ('Incorrect usage'); 33 end 34 case '()' 35 % Transform: obj(index) --> obj.data_(index) 36 r = subsref (obj.data_, S); 37 otherwise 38 error ('Incorrect usage'); 39 end 40 end 41 42 function obj = subsasgn (obj, S, B) 43 switch (S(1).type) 44 case '.' 45 switch (S(1).subs) 46 case 'data' 47 % Transform: obj.data --> obj.data_ 48 if length(S)>1 49 B = subsasgn (obj.data_, S(2:end), B); 50 end 51 obj.data_ = B; 52 case 'alldata' 53 % Transform: obj.data --> obj.data_(1:end) 54 if length(S)>1 55 B = subsasgn (obj.data_(1:end), S(2:end), B); 56 end 57 % This statement should trigger *builtin* subsref to evaluate 'end', 58 % then *builtin* subsasgn for the whole assignment expression 59 % 'end' here is also builtin 'end' 60 obj.data_(1:end) = B; 61 otherwise 62 error('Incorrect usage'); 63 end 64 case '()' 65 % Transform: obj(index) --> obj.data_(index) 66 obj.data_ = subsasgn (obj.data_, S, B); 67 otherwise 68 error ('Incorrect usage'); 69 end 70 end 71 72 function r = end (obj, k, n) 73 % We subtract 1 from the "real" end of obj.data_ 74 r = builtin ('end', obj.data_, k, n) - 1; 75 end 76 end 77end 78