Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing Assignment to array of structures?
Date: Sat, 10 Nov 2007 15:57:24 +0000 (UTC)
Organization: KTH
Lines: 86
Message-ID: <fh4kd4$r09$1@fred.mathworks.com>
References: <fc1m8v$b6r$1@fred.mathworks.com> <46e466c2$0$7346$426a74cc@news.free.fr> <fh4i46$5i8$1@fred.mathworks.com> <see-904A4E.10343610112007@71-129-133-66.dollamir.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1194710244 27657 172.30.248.38 (10 Nov 2007 15:57:24 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 10 Nov 2007 15:57:24 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1670
Xref: news.mathworks.com comp.soft-sys.matlab:436907



Doug Schwarz <see@sig.for.address.edu> wrote in message 
<see-904A4E.10343610112007@71-129-133-66.dollamir.com>...
> In article <fh4i46$5i8$1@fred.mathworks.com>,
>  "per isakson" <poi.nospam@bimDOTkthDOT.se> wrote:
> 
> > David Bateman <dbateman@free.fr> wrote in message 
<46e466c2
> > $0$7346$426a74cc@news.free.fr>...
> > > First Last wrote:
> > > > Hello, 
> > > > 
> > > > I have a variable 'data' that is a 1x2 structure 
array 
> > with
> > > > the fields in which:
> > > > 
> > > > data.times are 5x1 vectors 
> > > > data.mean are numbers
> > > > 
> > > > I can clearly access the data.mean and data.times 
> > values and
> > > > manipulate them, but is there a way I can assign 
each 
> > one of
> > > > the data.mean values in a vector, quickly, without 
a 
> > loop? 
> > > > 
> > > > For instance, let's say I want 
> > > > 
> > > > data(1).mean = 5;
> > > > data(2).mean = 7;
> > > > 
> > > > Is there a way to assign the vector [5 7] to 
data.mean?
> > > > Obviously this example there is only a marginal
> > > > computational penalty for doing this somewhat 
manually, 
> > but
> > > > for larger arrays of structures, this could be a 
> > nightmare.
> > > > I'm trying to vectorize this thing as much as 
possible.
> > > > 
> > > > Thanks in advance.
> > > > 
> > > 
> > > Maybe I'm missing something, but what is wrong with
> > > 
> > > data = struct('mean', {5,7})
> > > 
> > > 
> > > D.
> > 
> > Nothing is wrong as far as I can tell - with R2007a
> > 
> > >> data = struct('mean', {5,7})
> > data = 
> > 1x2 struct array with fields:
> >     mean
> > >> data
> > data = 
> > 1x2 struct array with fields:
> >     mean
> > >> data.mean
> > ans =
> >      5
> > ans =
> >      7
> > 
> > / per
> 
> The OP wanted to fill an existing field (mean) in a 
structure array with 
> numbers from a vector.  The statement above will create a 
new structure, 
> data, with only one field.  We don't know what the larger 
problem is and 
> whether there might be a better way to go about it.
> 
> -- 
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

Right - I missed the real question. / per