Why am I getting the error "Array indices must be positive integers or logical values"?

1 view (last 30 days)
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
madhan ravi on 12 Feb 2019
If you illustrate with an example and your desired output it would be clear what you are doing.

Sign in to comment.

Accepted Answer

Kevin Phung
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)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!