Reputation: 3313
In MATLAB's new object model (classdef
, etc): If I have an array of the object, and I call an ordinary method, is the methods called for each object, or for the entire array, i.e. is a single object passed into the method, or the entire array? I know that in the old model, it got dispatched as the entire array.
Upvotes: 1
Views: 491
Reputation: 1187
If you have:
classdef MyObject
methods
function foo(obj)
...
end
And you then call
>> foo(myObjArray)
Then the single call to foo() will receive the entire array. From there you can write code to handle a scalar case of obj or vector case of obj.
Upvotes: 6
Reputation: 12195
It depends on if your method is vectorized. For a trivial example:
function result = mySimpleMultiply(a,b)
result = a*b;
function result = myVectorizedMultiply(a,b)
result = a.*b;
Upvotes: -1