Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
preallocate a struct of structs

Subject: preallocate a struct of structs

From: Kirk

Date: 7 Jul, 2011 20:34:10

Message: 1 of 2

I am looking to preallocate a struct of structs. Where S is a struct and contains n copies of s' which is also a struct.

I think the structs can be empty. They are filled later in a for loop like this:

n = 1000;
for i = 1:n;
 S(i)=s';
end;

I am rather stumped on this. Thanks in advance

Subject: preallocate a struct of structs

From: Ben

Date: 7 Jul, 2011 21:32:09

Message: 2 of 2

"Kirk" <kwythers.nospam@umn.edu> wrote in message <iv5582$71g$1@newscl01ah.mathworks.com>...
> I am looking to preallocate a struct of structs. Where S is a struct and contains n copies of s' which is also a struct.
>
> I think the structs can be empty. They are filled later in a for loop like this:
>
> n = 1000;
> for i = 1:n;
> S(i)=s';
> end;
>
> I am rather stumped on this. Thanks in advance

If you don't care if they're empty, just set the last one:

n = 1000;
s = struct;
S(n) = s';

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us