Index in position 2 is invalid. Array indices must be positive integers or logical values.
2 次查看(过去 30 天)
显示 更早的评论
Hi. Im a newb. Im struggling to figure this part out. From what I can see, none of my indexes are negative. How can I fix this?
for iter=J:-1:1 % loop over
iter;
for indY=1:dimY
V(:, indY)=interp1(K, V(:, indY), K_prime, 'linear', 'extrap');
end
for ik=1:dimK % loop over all current cake sizes
for ik2=1:dimK
c=K(ik)*(1+r)+Y(iter)-K(ik2);
if c>0
U(ik, Y(iter), K(ik))=((c)^(1-eta)-1)/(1-eta)+beta*transY(indY, :).*(V(ik2, :)');
else
U(ik2)=-1e10;
end
end
[V(ik, iter), ind]=max(U); % optimizing over size of next period cake
A(ik, iter)=K(ind);
A_ind(ik, iter)=ind;
C(ik, iter)=K(ik)*(1+r)+Y(iter)-K(ind);
end
end
Im assuming the line I have bolded is the issue, but Im not entirely sure.
Thank you for your help!
0 个评论
回答(2 个)
Star Strider
2020-9-22
My guess is that the problem is using ‘Y(iter)’ and ‘K(ik)’ as indices in that assignment. They may not be integers greater than 0, or logical values. All the other array references appear to be correct
0 个评论
Image Analyst
2020-9-22
A thorough explanation of the error is given in the FAQ: https://matlab.fandom.com/wiki/FAQ#.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!