help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: append field to struct array


From: bpabbott
Subject: Re: append field to struct array
Date: Thu, 22 Jul 2010 08:52:49 -0700 (PDT)

On 22 Jul, 2010,at 10:57 AM, Eric Chassande-Mottin <address@hidden> wrote:

hi Octavers,

is there a fast way to append a new field to an existing struct array

ie., something that would replace the for loop in the bottom code

octave3.2:1> a(1).a=0; a(2).a=1; a(3).a=2;
octave3.2:2> a
a =
{
1x3 struct array containing the fields:

a
}

octave3.2:3> b=[3,4,5];
octave32:4> for n=1:rows(a),a(n).b=b(n);endfor

when the array is large, the above is quite slow.

thanks, eric

Try ...
 
    [a.b] = num2cell(b){:}

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]