フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
ved
ved 2015 年 11 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 11 月 3 日
編集済み: Walter Roberson 2015 年 11 月 3 日
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 2015 年 11 月 3 日

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by