Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Growable data structure in MATLAB

I need to create a queue in matlab that holds structs which are very large. I don't know how large this queue will get. Matlab doesn't have linked lists, and I'm worried that repeated allocation and copying is really going to slow down this code which must be run thousands of times. I need some sort of way to use a growable data structure. I've found a couple of entries for linked lists in the matlab help but I can't understand what's going on. Can someone help me with this problem?

like image 383
rlbond Avatar asked Apr 12 '10 20:04

rlbond


People also ask

How do you define a data structure in MATLAB?

A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a structure using dot notation of the form structName. fieldName .

Can you concatenate structures in MATLAB?

To concatenate structures, they must have the same set of fields, but the fields do not need to contain the same sizes or types of data. Just as concatenating two scalar values such as [1,2] creates a 1-by-2 numeric array, concatenating struct1 and struct2 creates a 1-by-2 structure array.

How do I see the structure of a structure in MATLAB?

Structures store data in containers called fields, which you can then access by the names you specify. Use dot notation to create, assign, and access data in structure fields. If the value stored in a field is an array, then you can use array indexing to access elements of the array.

How do you create an empty struct in MATLAB?

s = struct([]) creates an empty (0-by-0) structure with no fields. s = struct( obj ) creates a scalar structure with field names and values that correspond to properties of obj . The struct function does not convert obj , but rather creates s as a new structure.


1 Answers

I posted a solution a while back to a similar problem. The way I tried it is by allocating the array with an initial size BLOCK_SIZE, and then I keep growing it by BLOCK_SIZE as needed (whenever there's less than 10%*BLOCK_SIZE free slots).

Note that with an adequate block size, performance is comparable to pre-allocating the entire array from the beginning. Please see the other post for a simple benchmark I did.

like image 111
Amro Avatar answered Sep 29 '22 00:09

Amro