MATLAB: Array of struct arrays with varying length

MATLABstruct

Ideally, my calculation needs to preallocate an array, myArray, (of predetermined length) in which each element is an array of structs — an array which may grow in length during the course of the calculation. These arrays of structs must grow independently, so at the end of the calculation, the array of structs in myArray(1) may have a different length than myArray(2), etc.
The memory need not be contiguous, neither for myArray nor for the array of structs myArray(i).
Trying this
myArray(1:10) = { [ struct('index',int32(0), 'result',[]) ] };
% ... later, when an element needs to grow:
myArray(1) = { myArray(1); [ struct('index', int32(0),'result',[]) ] };
fails on that last line with the message, "In an assignment A(:) = B, the number of elements in A and B must be the same."

Best Answer

A cell array can hold a struct array in each location, but a struct array location cannot hold a struct array directly. A struct array indexed at an element must be a structure scalar. That structure scalar could have a single field which held a struct array, though.
myArray{1} = [myArray{1}; struct('index', int32(0),'result',[]) ];