How can I create a class method which can be called to modify various class properties repeatedly
6 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Construct and Work with Object Arrays 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!