Using a method size in a Class without making class objects it into an array

Hi!
I'm working with a class with a property data and want to construct a method that checks the size of the data: NewClassObject.size. However when I implement this the object becomes an 'array', which seems to change how my subsref indexing () works:
without size():
NewClassObject =
NewClass with properties:
...
with size():
NewClassObject =
5x1 NewClass array with properties:
...
Is there anyway to name a method size without anything else changing?
The class is too big to post here and I have no good way of reducing it at the moment. But maybe some of you might have an answer anyway?
Thanks!
Cecilia

 Akzeptierte Antwort

The size function in MATLAB has a specific meaning and purpose. I strongly recommend that if you want a method of your class that will return the size of the data stored in the object, rather than the size of the object itself, that you call it something other than size. One possibility that comes to mind is datasize. Alternately, if the data is a public property of the object call size on the result returned by accessing the property instead of calling size on the object:
size(MyClassObjectInstance.data)

1 Kommentar

Thank you for that answer!
I think I will name it datasize, seems like an obvious name now that you say it.
The reason for making it a specific method was so that I could format the output size in a few different ways, because the class is a type of time series, and the first dimension of the data is the number of time instances. So I wanted to obtain (by providing input TimeSeries.datasize('option')) some of the following, at different occasions:
TimeSeriesMatrix3x3.datasize = nTimes x 3 x 3
TimeSeriesVector1x3.datasize = nTimes x 3
TimeSeriesScalar1x1.datasize = nTimes x 1
or
TimeSeriesMatrix3x3.datasize = 1 x 3 x 3
TimeSeriesVector1x3.datasize = 1 x 3
TimeSeriesScalar1x1.datasize = 1 x 1
or
TimeSeriesMatrix3x3.datasize = 1 x 3 x 3
TimeSeriesVector1x3.datasize = 1 x 1 x 3
TimeSeriesScalar1x1.datasize = 1 x 1 x 1
or
TimeSeriesMatrix3x3.datasize = 3 x 3
TimeSeriesVector1x3.datasize = 1 x 3
TimeSeriesScalar1x1.datasize = 1 x 1

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 29 Apr. 2016

Kommentiert:

am 29 Apr. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by