Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

why do i get this error? 'Subscript indices must either be real positive integers or logicals.' thanks for any help!!!

1 vue (au cours des 30 derniers jours)
ved
ved le 3 Nov 2015
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (2)

Walter Roberson
Walter Roberson le 3 Nov 2015
Modifié(e) : Walter Roberson le 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
Stalin Samuel le 3 Nov 2015

Cette question est clôturée.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by