I frequently use struct arrays to store various types of data in my MATLAB programs. For large arrays, it’s better to preallocate space in advance - although it’s not well-documented, the easiest way to do this is to initially assign a value to the largest array element you’ll need. For example:
>> dataset(1000).field1 =  dataset = 1x1000 struct array with fields: field1
Now, if you check, say, the 500th element:
>> dataset(500) ans = field1: 
you’ll see that space for the remaining 999 entries has been allocated.
- Add a comment // // Add to...