Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: how to assign multiple structure elements at once Date: Fri, 16 Nov 2012 11:53:17 +0000 (UTC) Organization: Marquette University Lines: 29 Message-ID: <k859fd$1fr$1@newscl01ah.mathworks.com> References: <k83bfk$1rf$1@newscl01ah.mathworks.com> <k83cl8$6ft$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-06-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1353066797 1531 172.30.248.38 (16 Nov 2012 11:53:17 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 16 Nov 2012 11:53:17 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2023544 Xref: news.mathworks.com comp.soft-sys.matlab:782917 "Matt J" wrote in message <k83cl8$6ft$1@newscl01ah.mathworks.com>... > "Fatih" wrote in message <k83bfk$1rf$1@newscl01ah.mathworks.com>... > > Hi, > > > > I'm trying to assign multiple values to second element of a field of multiple structure elements. Better I give you an example to explain that: > > > > let's say the values are = 1,2,3 > > structure is = a > > field is = s > > > > then the result should look like this: > > a(1).s(2) = 1 > > a(2).s(2) = 2 > > a(3).s(2) = 3 > ================= > > My answer to posts like these is always to question the way the data is being organized, so I'll do that again here. > > Given what you have above, it looks lik all a(i).s are the same size. If some a(j).s is of length 1, for example, this makes no sense. Assuming this to be the case, it probably makes sense for you to make 'a' a scalar struct instead and do > > a.s(:,2)=[1;2;3]; > > Either that, or hold s in a separate array. Hi Mat, Thanks for your post, however that does not help me much and the reason is the structure organization should not be like the one you gave with your post. Say I have 10 buses (a) operating daily in a route and I am sampling every hour the number of passengers (s) riding each of those buses. Some of those buses can be broken at any sampling time, and I am only recording that data for good buses. So if that bus does not work any more the number of passengers field will not be updated anymore. So by looking at this example a.s(:,2) = [1;2;3] does not work. Maybe I should change the organization or just use a for loop. I was thinking there can be a trick like deal function that fits here nicely.