Home > Blockchain >  MATLAB list-like data structure
MATLAB list-like data structure

Time:09-02

Does MATLAB have a data structure to which elements can be added and removed without copying all of data?

AFAIK it lacks a list (like in Python), so I'm trying to implement it, but unsure what to build it on. I figured cell array, but the linter suggests it's actually an array. One could implement it the long way where each element is a separate class, using handle classes as containers as pointers, but I'm guessing that's not efficient in MATLAB.

struct? Extend a cell array each time its length is exceeded? More important than not copying the list is to not copy its contents, namely arrays.

Edit: I implemented Pythonic list and dict based on cellarray and containers.Map, here.

CodePudding user response:

Mathworks themselves have an example linked-list implementation, where each elements seemed to be an instance of a class. It's bound to be less efficient than a uniform array in many operations, but could be ideal for many others.

Alternatively, you can relay on Java LinkedLists like discussed in here. Whether performance improves depends on the actual usage scenario.

I guess the most efficient way will be using MEX function to call C routines, save for hardware specific optimizations. That's likely to be far-fetched for most applications that starts in MATLAB.

  • Related