I have an established object I would like to overload one of its properties by creating a method of the same name.
My idea for solving this predicament is to create a method of the same name as the property that simply filters out the non-positive inputs and returns the positive inputs that the original property would otherwise return. Currently, the method of myProp is underlined red because its use is "inconsistent with its previous use".
function obj = myObj()
obj.myProp = randi(9,5,3);
function myProp_Output = myProp(rows,columns)
idx0 = rows == 0;
myProp_Output = zeros(length(rows),columns);
myProp_Output(~idx0,columns) = myObj.myProp(rows(~idx0),columns);
I would like to do this because I've created some code that creates arrays for indexing that might have some non-positive indices (zero) and sometimes I use these arrays to index into a property of my object. I've read a little documentation on overloading in MATLAB but I haven't yet found anything that would help me overload a property of an object with a method.
obj = myObj();
indices = [0 3 5];
I would like this to be the output:
[0 0 0; obj.myProp(3,:); obj.myProp(5,:)]