Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: how to assign multiple structure elements at once
Replies: 5   Last Post: Nov 17, 2012 10:01 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Matt J

Posts: 4,996
Registered: 11/28/09
Re: how to assign multiple structure elements at once
Posted: Nov 15, 2012 1:35 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.