why do i get this error? 'Subscript indices must either be real positive integers or logicals.' thanks for any help!!!
Info
This question is closed. Reopen it to edit or answer.
Show older comments
h=0.1;
t=36;
N=(t/h);
t=zeros(1,N+1);
p=zeros(1,N+1);
t(1)=0;
p(1)=87;
for n=1:N
t(n+1)=t(n)+h;
u=sin((2*pi*t)/12);
H=15*[nthroot(u,15)+1]
p1(n+1)=p(n)+h*[(0.016*p(n)*(100-p(n)))-H(n)];
p(n+1)=p(n)+(h/2)*[[(0.016*p(n)*(100-p(n)))-H(t)]+[(0.016*p(n+1)*(100-p(n+1)))-H(n+1)]];
end
Answers (2)
Walter Roberson
on 3 Nov 2015
Edited: Walter Roberson
on 3 Nov 2015
Your line
p(n+1)=p(n)+(h/2)*[[(0.016*p(n)*(100-p(n)))-H(t)]+[(0.016*p(n+1)*(100-p(n+1)))-H(n+1)]];
includes the subexpression H(t). H(t) denotes indexing the vector H at the locations designated in t. But t is, at that point, a vector of values that are not integers, so this is going to fail.
In the other places you use H, you use H(n) or H(n+1) which do not have that problem.
Note: in MATLAB, [] designate building matrices or vectors, rather than being parenthesis. There are a number of cases where you would get away with using [] instead of () but it will cause problems eventually.
Stalin Samuel
on 3 Nov 2015
0 votes
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!