[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: programming help
From: |
c. |
Subject: |
Re: programming help |
Date: |
Wed, 17 Nov 2010 18:15:32 +0100 |
On 17 Nov 2010, at 17:52, insipido wrote:
> Hi
> I am not so good for programing, but I do my best.
> I wanted do know if it is possible to obtain in return a numbered
> variable.
> 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
>
> the result is:
>
> c=11
> c=12
> c=13
> c=14
> c=15
>
> but then, 'c' ends with value =15, but what about I want to save in
> different variables other results, like:
>
> c1=11
> c2=12
> c3=13
> c4=14
> c5=15
>
> and in that way I could easily call them independently.
>
> any idea, please help me.
>
> thanks
>
> victor./
>
why not use a vector rather than a set of variables with a number in the name?
for example:
a = 5;
b = 2*a;
for i = 1:a
c(i) = b+i
endfor
then
c(1) is equal to 11
c(2) is equal to 12
...
c(5) is equal to 15
so you can access all the values indipendently as you wanted to
c.