help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programming help


From: Przemek Klosowski
Subject: Re: programming help
Date: Wed, 17 Nov 2010 12:46:25 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Fedora/3.1.6-1.fc14 Lightning/1.0b2 Thunderbird/3.1.6

I think the original poster would be better off using the array
calculations, which are after all Octave's strength. For example:

N=5
a=1:N
b=2*N
c=b+a

and then c ends up being a vector [ 11   12   13   14   15 ]
so you can refer to c(1) which is 11, c(2) equal to 12, etc.


On 11/17/2010 11:57 AM, OCuanachain, Oisin (Oisin) wrote:
> You could use an array:
>
> for i = 1:a
>      c(i) = b+i;
> endfor
>
> Then you would have
> c(1) = 11
> c(2) = 12
> etc.
>
> OR you could use eval()
>
> for i = 1:a
>      eval(['c' num2str(i) ' = b+i']);
> endfor
>
> This would give you exactly what you requested:
> c1 = 11
> c2 = 12
> etc
>
> -----Original Message-----
> From: insipido [mailto:address@hidden

> I would like to save in different variables the result of a for cycle.
>
> for example:
>
> a = 5;
> b = 2*a;
> for i = 1:a
>      c = b+i
> endfor


reply via email to

[Prev in Thread] Current Thread [Next in Thread]