Complete the code to define a simple MATLAB class.
classdef [1]
properties
Value
end
endThe keyword classdef is followed by the class name, here MyClass.
Complete the code to add a method that sets the property value.
methods
function obj = setValue(obj, val)
obj.Value = [1];
end
endThe input val is assigned to the property Value.
Fix the error in the constructor method to initialize the property.
methods
function obj = [1](val)
if nargin > 0
obj.Value = val;
end
end
endThe constructor method must have the same name as the class, here MyClass.
Fill both blanks to create a method that returns the property value.
methods
function val = [1](obj)
val = obj.[2];
end
endThe method getValue returns the property Value.
Fill all three blanks to create a class with a property, constructor, and a method to double the value.
classdef [1] properties [2] end methods function obj = [1](val) obj.[2] = val; end function obj = doubleValue(obj) obj.[2] = obj.[2] * 2; end end end
The class name is MyClass, the property is Value, and the constructor matches the class name.
