I have a created a simple class to try and learn more about classes in MATLAB
Below is my class.
classdef ClassTest < handle
methods
function t1 = testone(numOne, numTwo)
t1 = t2(numOne, numTwo);
end
function t2 = testtwo(numOne, numTwo)
t2 = numOne / numTwo;
end
end
end
So I create an instance of my class using the line of code below.
myClass = ClassTest;
I then call the function testone with the line below.
v = myClass.testone(20,5);
But get the error message "Error using ClassTest/testone Too many input arguments." I don't understand this?
I tried leaving the 5 out and it actually got to the line t1 = t2(numOne, numTwo) but then didn't recognize the function t2 which I find surprising? Not following what is going on here?
Update
If I make the methods static I no longer get the error message about there being to many input arguments however it does not recognise the testtwo function when called from the function testone unless I put ClassTest.testtwo. Still seems strange to me
Solution
So bit of playing around I now have the code working however not sure I fully understand what is happening.
The two functions should look like below,
function t1 = testone(obj, numOne, numTwo)
t1 = obj.testtwo(numOne, numTwo);
end
function t2 = testtwo(obj, numOne, numTwo)
t2 = numOne / numTwo;
end