Object property as function argument
Show older comments
Hey all, I want one of the functions in my class to contain an input parameter which is a property of an object of that class.
For example:
classdef MyClass
properties
myproperty = cell(8)
end
methods
x = myfunction1 (mycellarray)
end
myfunction2 (myobject)
y = myfunction1(myobject.myproperty)
end
end
end
However, I get the error
Undefined function 'myfunction1' for input arguments of type 'cell'.
It's nothing to do with cells in particular: if I try to pass a string, to myfunction3, which takes strings as an input, I get
Undefined function 'myfunction3' for input arguments of type 'char'.
Please help!
Accepted Answer
More Answers (1)
Vandana Rajan
on 12 Jun 2017
Hi,
You may see the code below. This doesn't throw any error.
classdef MyClass
properties
myproperty = cell(8)
end
methods
function x = myfunction1 (myproperty1)
x = myproperty1;
end
function myfunction2 (obj)
y = myfunction1(obj.myproperty);
end
end
end
Categories
Find more on Class File Organization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!