Array indices must be positive integers or logical values
6 views (last 30 days)
Show older comments
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
Answers (0)
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!