Array indices must be positive integers or logical values
1 view (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
2 Comments
Geoff Hayes
on 8 Apr 2020
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?
Answers (0)
See Also
Categories
Find more on Genomics and Next Generation Sequencing 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!