[prev in list] [next in list] [prev in thread] [next in thread] 

List:       scilab-users
Subject:    Re: [scilab-Users] Keeping track of for loops
From:       "Eric Dubois" <grocer.toolbox () gmail ! com>
Date:       2008-02-29 8:24:45
Message-ID: b04eeae20802290024o5e5cc601r7a2b585e6bf5a38e () mail ! gmail ! com
[Download RAW message or body]

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@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
>

[Attachment #3 (text/html)]

<div>Do :</div>
<div>&nbsp;</div>
<div>for i=1:n</div>
<div>&nbsp;&nbsp;&nbsp; execstr(&#39;x&#39;+string(i)+&#39;=&#39;+string(i))</div>
<div>end<br>&nbsp;</div>
<div>Or more efficiently (but less general) :</div>
<div>&nbsp;</div>
<div>execstr(&#39;x&#39;+string([1:n])+&#39;=&#39;+string([1:n])</div>
<div>&nbsp;</div>
<div>Eric.</div>
<div><br>&nbsp;</div>
<div><span class="gmail_quote">2008/2/29, Matthew Albrecht &lt;<a \
href="mailto:mattyalbrecht@gmail.com">mattyalbrecht@gmail.com</a>&gt;:</span> \
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; \
BORDER-LEFT: #ccc 1px solid">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 &#39;x1&#39; to \
&#39;xn&#39;.<br> In its most simplest form, I would like to be able to do \
this:<br><br>for i=1:n<br>x=i<br>end<br> <div style="MARGIN-LEFT: \
40px">x1=1<br>&nbsp;</div> <div style="MARGIN-LEFT: 40px">x2=2<br>&nbsp;</div>
<div style="MARGIN-LEFT: 40px">....<br>&nbsp;</div>
<div style="MARGIN-LEFT: 40px">xn=n<br>&nbsp;</div><br>Where currently it outputs<br>
<div style="MARGIN-LEFT: 40px">x=1<br>&nbsp;</div>
<div style="MARGIN-LEFT: 40px">x=2<br>&nbsp;</div>
<div style="MARGIN-LEFT: 40px">...<br>&nbsp;</div>
<div style="MARGIN-LEFT: \
40px">x=n<br><br>&nbsp;</div>Thanks<br>Matt<br></blockquote></div><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic