[scilab-Users] Keeping track of for loops

Eric Dubois grocer.toolbox at gmail.com
Sun Mar 2 22:14:36 CET 2008


I am not sure to understand the flavour of the problem, but, in the case
shown below:
for i=1:5
  x=[1:5;6:10];
  execstr('x'+string(i)+'='+string(i)+'*x')
end

Works as intended.

Eric.

2008/3/1, Matthew Albrecht <mattyalbrecht at gmail.com>:
>
> I'm now having problems getting this to work with a matrix. The string
> function only outputs the sum from the last item in the matrix.
> e.g.
>
> for i=1:5
> x=[1:5;6:10];
> execstr('x'+string(i)+'='+string(i*x))
> end
>
> x3=
> 30
>
> but I need the full matrix outputted i.e.
> x3=
> 3.     6.    9.   12.  15.
> 18.  21.  24.   27.  30.
>
> Matt
>
> On 01/03/2008, Matthew Albrecht <mattyalbrecht at gmail.com> wrote:
> >
> > Thanks, works well.
> >
> > On 29/02/2008, Eric Dubois <grocer.toolbox at gmail.com> wrote:
> > >
> > > Do :
> > >
> > > for i=1:n
> > >     execstr('x'+string(i)+'='+string(i))
> > > end
> > >
> > > Or more efficiently (but less general) :
> > >
> > > execstr('x'+string([1:n])+'='+string([1:n])
> > >
> > > Eric.
> > >
> > >
> > > 2008/2/29, Matthew Albrecht <mattyalbrecht at gmail.com>:
> > > >
> > > > I would like to keep track of the output of a for loop, so that each
> > > > output is assigned sequentially to a new variable from 'x1' to 'xn'.
> > > > In its most simplest form, I would like to be able to do this:
> > > >
> > > > for i=1:n
> > > > x=i
> > > > end
> > > > x1=1
> > > >
> > > > x2=2
> > > >
> > > > ....
> > > >
> > > > xn=n
> > > >
> > > >
> > > > Where currently it outputs
> > > > x=1
> > > >
> > > > x=2
> > > >
> > > > ...
> > > >
> > > > x=n
> > > >
> > > >
> > > > Thanks
> > > > Matt
> > > >
> > >
> > >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20080302/a5f9a819/attachment.htm>


More information about the users mailing list