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:18:30 +0000 (UTC)
Organization: KTH
Lines: 60
Message-ID: <fh4i46$5i8$1@fred.mathworks.com>
References: <fc1m8v$b6r$1@fred.mathworks.com> <46e466c2$0$7346$426a74cc@news.free.fr>
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 1194707910 5704 172.30.248.38 (10 Nov 2007 15:18:30 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 10 Nov 2007 15:18:30 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1670
Xref: news.mathworks.com comp.soft-sys.matlab:436903



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