Object property as function argument
이전 댓글 표시
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!
채택된 답변
추가 답변 (1개)
Vandana Rajan
2017년 6월 12일
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
카테고리
도움말 센터 및 File Exchange에서 Class File Organization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!