help-octave
[Top][All Lists]
Advanced

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

Re: storing values generated in a 'for'loop


From: Ben Abbott
Subject: Re: storing values generated in a 'for'loop
Date: Wed, 23 Apr 2008 22:10:42 -0400


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


reply via email to

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