How can I create a class method which can be called to modify various class properties repeatedly
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello! I have a class with a number of properties, and I want to write a method which can be called within the class and use properties as arguments in order to change the value of the input properties. Something like this.
classdef myClass < handle
properties
property1
property2
property3
property4
end
methods
function output = myFunction(input)
output = input;
end
% constructor
function object = myClass
% call the same function to modify various propeties
object.property1 = myFunction(object.property2);
object.property3 = myFunction(object.property4);
end
end
end
I know this code doesnt work and I have been using a handle class so my methods can modify properties. I know that the first argument generally has to be the object but I have no use for it in the function. Is there a way to pass properties and modify them similar to above? Any help would be great thanks!
댓글 수: 3
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!