[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: storing values generated in a 'for'loop
From: |
asha g |
Subject: |
Re: storing values generated in a 'for'loop |
Date: |
Wed, 23 Apr 2008 22:57:53 -0700 (PDT) |
Thanks Ben.
It works. I don't get the results I want but that
problem is not a programming one.
BTW, I am not confused between scalars and vectors.
Just how they are written in this program. I did not
know of numel till now.
Asha
--- Ben Abbott <address@hidden> wrote:
>
> On Apr 23, 2008, at 9:23 PM, asha g wrote:
>
> > I have a program in which I am iterating V from
> -80 to
> > 80 to generate values of n. then I have to plot n
> vs
> > V.
> >
> > I wrote
> >
> > for iter = -80:10:80
> > V= iter;
> > [alphan,betan,alphah,betah,alpham,betam]=
> ratcon(V);
> > [n,m,h] =
> > gatpara2(alphan,betan,alphah,betah,alpham,betam);
> >
> > n(iter) = n;
> > m(iter)= m;
> > h(iter)= h;
> > V(iter) = V;
> > end
> > plot(V,n,'r')
> >
> > The problem I am having is that the command
> > n(iter) = n; generates an error message saying
> > subscript indexes must be real positive integers
> or
> > logicals.
> > How do I write those statements in order that they
> > store all values of n,m,h and V during the
> iteration?
> > I am not sure if you need the function files too
> to
> > help me. If so, can send them.
> > Thanks for your help.
> > Asha
>
>
> You confusing scalars with vectors. Try something
> like the code below.
>
> V = -80:10:80;
> n = zeros(size(V));
> m = zeros(size(V));
> h = zeros(size(V));
> for iter = 1:numel(V)
> [alphan,betan,alphah,betah,alpham,betam]=
> ratcon(V(iter));
> [n(iter),m(iter),h(iter)] =
> gatpara2(alphan,betan,alphah,betah,alpham,betam);
> endfor
> plot(V,n,'r')
>
> This is a good example to introduce yourself to the
> difference between
> vectors and scalar, and how individual elements of
> vectors are
> addressed.
>
> Ben
>
Goals too clearly defined can become blinkers.
Mary Catherine Bateson
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ