MATLAB Answers

How to get multiple class instances in function?

3 views (last 30 days)
Mathew
Mathew on 14 Apr 2020
Answered: Sean de Wolski on 14 Apr 2020
I wanna get two object instance at once in my function like this
classdef MyClass
properties
value
end
methods
function tmp=myfunc(obj1, obj2)
tmp=obj1.value+obj2.value
end
end
end
and in console
a=myclass;
b=myclass;
a.myfunc(a,b);
and error occurs.
it says too many arguments
How to get multiple class instance at once?

  0 Comments

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 14 Apr 2020
a.myfunc(b)
% or
myfunc(a, b)
When you call a.function it passes a as the first input so right now you're doing the equivalent of myfunc(a,a,b)

  0 Comments

Sign in to comment.

More Answers (0)