Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: struct command in loop
Replies: 5   Last Post: Apr 1, 2013 6:23 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Kian Posts: 12 Registered: 4/16/13
Re: struct command in loop
Posted: Apr 1, 2013 6:23 PM
 Plain Text Reply

TideMan <mulgor@gmail.com> wrote in message <b0abc0d1-a334-4736-b94b-919820258b30@googlegroups.com>...
> On Tuesday, April 2, 2013 6:41:09 AM UTC+13, Kian wrote:
> > I have a for loop, where in each loop I want to put a 12 by 4 matrix into a structure.
> >
> > The 12 by 4 matrix is generated in each loop, so then I want to assign each newly generated matrix into a new field of the same structure.
> >
> >
> >
> > So for example I have this matrix called "Mat", and its elements are regenerated in each loop, so in the first loop I can write something like
> >
> >
> >
> > field = 'field1'
> >
> > mystruct = struct (field, Mat)
> >
> >
> >
> > then in the second loop I have to write something to change my "field" script, like in the second loop it should be changed to
> >
> >
> >
> > field = 'field2'
> >
> >
> >
> > so that once struct is run, it assigns the new "Mat" to another field. My problem is how to write field so that is changes from 'field1' to 'field2' and so on in each loop!
> >
> >
> >
> > Sorry, I know this is easy for you guys out there, but I m sort of a novice!
> >
> >
> >
> > I appreciate any help.

>
> Two things come to mind:
> 1. If all the matrices are the same size, why not use a multi-dimensional array instead:
> A(12,4,iz)
> 2. If you need to use a structure, maybe use a structure array:
> mystruct(iz).field=A;
> where iz is the loop index.

Thank you Tideman. I got it.

Date Subject Author
4/1/13 Guest
4/1/13 Steven Lord
4/1/13 Kian
4/1/13 Derek Goring
4/1/13 Kian
4/1/13 Kian

© The Math Forum at NCTM 1994-2018. All Rights Reserved.