passing a cell array of objects to a method

5 views (last 30 days)
I'd like to send an array of objects to a method (n=1 to many). Is there a syntax that allows the first argument of a method to be a cell array of class objects? Of course this could be done with varargin and parsing inputs, but this seems more cumbersome than need be.
thanks

Accepted Answer

Daniel Shub
Daniel Shub on 19 Jul 2011
Static methods in MATLAB do not require an object of the class, so you could pass it your cell array. I am not sure if a static method of a class, that takes in an object of the class via a cell array, would have access to private properties and methods.

More Answers (1)

Walter Roberson
Walter Roberson on 18 Jul 2011
If this array is hetrogenous then is there a reason you are using a cell array instead of an array of the appropriate class?
If the array is homogenous then which element of the cell array should be examined in order to determine which object class is to be invoked?
  2 Comments
Aaron Gruber
Aaron Gruber on 19 Jul 2011
Hi Walter,
The array is of homogeneous class, but each element is an array of objects. I don't want to concatenate them as I'll loose the grouping information contained in the array. The method in question is to parse the arrays in order to compute stats and plot. This is for analysis of a rich data set: each array of objects correspond to related data, and I'd like to compare between an arbitrary number of such arrays. I am developing this as a function, but there would be some data access/protection conveniences by making it a method.
For now, I can come up with a non-optimal workaround, but this is something I'll run into again. So I'm throwing this out there in case someone knows if there is syntax that will allow this to work as a method.
thanks
Walter Roberson
Walter Roberson on 19 Jul 2011
A cell array is not a class of anything other than "cell".
I suspect you would be better off defining a class which was a "collection" of your class objects. You could probably override horzcat() and vertcat() to give you semantics such as [] being able to construct the container class.

Sign in to comment.

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!