Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!news01.roc.ny.POSTED!53ab2750!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorizing Assignment to array of structures?
References: <fc1m8v$b6r$1@fred.mathworks.com>
In-Reply-To: <fc1m8v$b6r$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 39
Message-ID: <qGZEi.15770$B25.7823@news01.roc.ny>
X-Complaints-To: abuse-news@frontiernet.net
X-Trace: 52616e646f6d4956aa8b238aa2f708cbb34fb346320b3dec7e72a8441ef2a49afcf0ab3e309f04f99daba592c6ef1eec75a2fabe00d524ae069613e2eb3a1990178ccff16bbf55996b8960b541e277adb63f7d30f816e829a97fd16f22f7ae7887ef1f159756d428bc525d3301430310
X-Abuse-Info: Please be sure to forward ALL headers so that we may process your complaint properly.
NNTP-Posting-Date: Sun, 09 Sep 2007 21:35:18 UTC
Date: Sun, 09 Sep 2007 21:35:18 GMT
Xref: news.mathworks.com comp.soft-sys.matlab:427577



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?

If you are creating data from scratch then use

   data = struct('mean',num2cell([5 7]));

If data already exists and is the right size then use

   c = num2cell([5 7]);
   [data.mean] = c{:};

or if you are using a version of MATLAB before 7:

   c = num2cell([5 7]);
   [data.mean] = deal(c{:});


-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.