Array indices must be positive integers or logical values
조회 수: 3 (최근 30일)
이전 댓글 표시
I am using the below code. When it gets to the line "left(j) = u - U(i-j+1)", it shows error "Array indices must be positive integers or logical values." How should I solve this issue? Any help would be appreciated!
clear all;
clc;
p=2
U = [0 0 0 1 2 3 3 3]
u=1
i=4
N = zeros(1,p+1)
left = zeros(1,p)
right = zeros(1,p)
N(1) = 1
for j=1:p
left(j) = u - U(i-j+1)
right(j) = U(i+j) - u
saved = 0
for r = 0:j-1
temp = N(r+1)/(right(r+1) + left(j-r))
N(r+1) = saved+right(r+1)*temp
saved = left(j-r)*temp
end
N(j+1) = saved
end
댓글 수: 2
Geoff Hayes
2020년 4월 8일
Hossein - the above code seems to run fine for me...though I suppose if you chose different p and/or i then I can see how i-j+1 may be zero or negative. Since p is 2 and i is 4 then your only indices are 4 and 3 which are valid...but perhaps you want to make use of all the elements of U?
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
