This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Memory Requirements for a Structure Array

Structure arrays do not require completely contiguous memory. However, each field requires contiguous memory, as does the header that MATLAB® creates to describe the array. For very large arrays, incrementally increasing the number of fields or the number of elements in a field results in Out of Memory errors.

Allocate memory for the contents by assigning initial values with the struct function, such as

newStruct(1:25,1:50) = struct('a',ones(20),'b',zeros(30),'c',rand(40));

This code creates and populates a 25-by-50 structure array S with fields a, b, and c.

If you prefer not to assign initial values, you can initialize a structure array by assigning empty arrays to each field of the last element in the structure array, such as

newStruct(25,50).a = [];
newStruct(25,50).b = [];
newStruct(25,50).c = [];

or, equivalently,

newStruct(25,50) = struct('a',[],'b',[],'c',[]);

However, in this case, MATLAB only allocates memory for the header, and not for the contents of the array.

For more information, see:

Was this topic helpful?