Array indices must be positive integers or logical values
1 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!