How can one create an object in MATLAB that behaves like an array?

조회 수: 4 (최근 30일)
Tyler L
Tyler L 2019년 1월 24일
댓글: Tyler L 2019년 1월 29일
I need to build a tool that will allow access to extremely large data sets where the user will typically only work with smaller slices at a time. I know newer versions of MATLAB have tools built-in that can help deal with some of these issues, but I need to be backwards compatable with fairly old versions of MATLAB. The data is binary and can be stored across multiple files (approx 2 GB chunks). I need to expose this to the user as though they were all combined together and behave like a normal 3-dimensional vector which can be arbitrarily sliced.
Currently, I return a struct to the user that contains a handle to a function in place of the actual data matrix when the data set is too large for memory. This function is designed to be called like a normal vector slicing operation, and in return, it pieces together the desired components from the memory maps and returns an array to the user.
I would like to put something together that behaves more like an array without the need for the function call when its not necessary. For example, if the user were to use the size command, I'd rather it just return the size instead of actually having to build the thing to then figure out the size. Or, if the user tries to print the array at the prompt, they get an indication that it's a function handle, rather than a preview of the data set. Same thing with the preview in the variable list. Additionally, the user cannot use the end keyword when trying to build a slice, though I am able to use a plain colon operator. As an aside, if the user is trying to get a larger slice, they then have to pass an entire vector identifying the slice to the function call that has to be generated in memory. It would be nice for this to not happen.
So, where would I need to start to think about doing something like this? Does this need to be done in MEX, or can it be done in MATLAB code? I'm open to any thoughts in general.

채택된 답변

Edric Ellis
Edric Ellis 2019년 1월 29일
To make an object in MATLAB that is a single object that behaves like an array, you need to overload a bunch of methods to do with the object's size and indexing behaviour. There's some information on this page: https://uk.mathworks.com/help/matlab/matlab_oop/class-with-modified-indexing.html , and this shows that you can do everything using only MATLAB code. You need to overload:
  1. subsref and subsasgn
  2. size
  3. numArgumentsFromSubscripts
  4. end
  5. probably cat, vertcat, and horzcat
  댓글 수: 1
Tyler L
Tyler L 2019년 1월 29일
This is exactly the information I'm looking for! Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by