Why am I getting the error "Array indices must be positive integers or logical values"?
1 view (last 30 days)
Show older comments
Siddart Fredrick
on 12 Feb 2019
Commented: Siddart Fredrick
on 12 Feb 2019
I have the following code. I am unsure as to why I am recieving this error when the array indices is always positive as far as I can tell.
function[f] = ntdd(x,f)
n = length(f);
for i = 2:n
for j = n:-1:1
f(j) = ((f(j)-f(j-1))/(x(j)-x(j-(i+1))));
end
end
end
3 Comments
madhan ravi
on 12 Feb 2019
If you illustrate with an example and your desired output it would be clear what you are doing.
Accepted Answer
Kevin Phung
on 12 Feb 2019
for i = 2:n
for j = n:-1:1
f(j) = ((f(j)-f(j-1))/(x(j)-x(j-(i+1))));
end
end
looks like when j is 1, you have a f(j-1) which gives you f(0)
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!