Array indices must be positive integers or logical values.

Hello everyone! I am having a hard time making the following function work, as I keep getting the message "Array indices must be positive integers or logical values". What could be the problem??
function[p]=map_funct(alpha, beta, lambda, gamma, Num, gf, gc, w, F, r, D, N, p0)
alpha=2.1;
beta=15;
D=1;
F=3;
r=0.01;
Num=100;
gf=0.5;
gc=0.3;
lambda=1;
gamma=0.35;
w=0.5;
N=1200;
p0=2.95;
p=zeros(N,1);
p(1)=p0;
for k=1:N-2
p(k+1)=p(k)+gamma*Num*((w*gf*(F-p(k))+(1-w)*gc*(p(k)-F))./(1+exp(-lambda*(alpha*((D/F)-r)+beta*((p(k-1)-p(k-2))./p(k-1))))));
%
% line([p(k),p(k)],[p(k),p(k+1)]);
% line([p(k),p(k+1)],[p(k+1),p(k+1)]);
%
%
end

2 件のコメント

KSSV
KSSV 2020 年 4 月 9 日
You have used p(k-1), p(k-2) in your formula.....when your indices start with 2...p(k-2) ,will be zero and you will get error.
Carolina Biliotti
Carolina Biliotti 2020 年 4 月 9 日
yep! that was it!!! thank you so much!

サインインしてコメントする。

 採用された回答

madhan ravi
madhan ravi 2020 年 4 月 9 日

0 投票

1-1=0, 1-2=-1, MATLAB likes only positive numbers greater than zero :)

1 件のコメント

Carolina Biliotti
Carolina Biliotti 2020 年 4 月 9 日
Got it, i corrected it and now is running smoothly :) thanks alot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by