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:
Assign an array to an array of structures

Subject: Assign an array to an array of structures

From: LP

Date: 17 Nov, 2011 02:19:10

Message: 1 of 4

Hi -

heres some psuedo code for what i'm trying to do

% construct a test
[test(1:10).m] = deal(9);

% pull out into an array
x = [test.m];

% do some op
x= rand(size(x));

% **PROBLEM : Can't reinsert here fast? any ideas

[test.m] = x; ?????

Many thanks, Lyle

Subject: Assign an array to an array of structures

From: ade77

Date: 17 Nov, 2011 02:57:11

Message: 2 of 4

"LP" wrote in message <ja1quu$d08$1@newscl01ah.mathworks.com>...
> Hi -
>
> heres some psuedo code for what i'm trying to do
>
> % construct a test
> [test(1:10).m] = deal(9);
>
> % pull out into an array
> x = [test.m];
>
> % do some op
> x= rand(size(x));
>
> % **PROBLEM : Can't reinsert here fast? any ideas
>
> [test.m] = x; ?????
>
> Many thanks, Lyle

I think you forgot the word "deal", in your last line of code:
[test.m] = deal(x);

not sure if this address ur question

Subject: Assign an array to an array of structures

From: LP

Date: 17 Nov, 2011 04:35:29

Message: 3 of 4

I believe deal only works for constants, not vectors.
Thanks, Lyle


"ade77 " <ade100a@gmail.com> wrote in message <ja1t67$jen$1@newscl01ah.mathworks.com>...
> "LP" wrote in message <ja1quu$d08$1@newscl01ah.mathworks.com>...
> > Hi -
> >
> > heres some psuedo code for what i'm trying to do
> >
> > % construct a test
> > [test(1:10).m] = deal(9);
> >
> > % pull out into an array
> > x = [test.m];
> >
> > % do some op
> > x= rand(size(x));
> >
> > % **PROBLEM : Can't reinsert here fast? any ideas
> >
> > [test.m] = x; ?????
> >
> > Many thanks, Lyle
>
> I think you forgot the word "deal", in your last line of code:
> [test.m] = deal(x);
>
> not sure if this address ur question

Subject: Assign an array to an array of structures

From: Matt J

Date: 17 Nov, 2011 14:29:30

Message: 4 of 4

"LP" wrote in message <ja1quu$d08$1@newscl01ah.mathworks.com>...
>
>
> % **PROBLEM : Can't reinsert here fast? any ideas
>
> [test.m] = x; ?????
=================

xc=num2cell(x);
[test.m]=deal(xc{:});

By "fast" I'm assuming you mean, "in just a few lines" and not "with high computational speed". If speed is a priority, you shouldn't be storing in structs in the first place.

Tags for 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