Anyway to Pre-allocate Memory for Struct

Is there anyway to pre-allocate memory for a struct?
I have a
1x2 struct with 2 fields.
>> s = struct('Name',0,'Name2',0)
But, it comes up as a 1x1 struct.

답변 (3개)

Walter Roberson
Walter Roberson 2015년 7월 17일

0 개 추천

s = struct('Name',{0,0},'Name2',{0,0});
That is, use a cell array, one entry per struct member.
Stephen23
Stephen23 2022년 12월 14일
이동: Stephen23 2022년 12월 14일
Here are two generalizable, easily expandable appraches:
S = repmat(struct('Name',[],'Name2',[]),1,2)
S = 1×2 struct array with fields:
Name Name2
C = cell(1,2);
S = struct('Name',C,'Name2',C)
S = 1×2 struct array with fields:
Name Name2

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2015년 7월 17일

이동:

2022년 12월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by