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

1 回表示 (過去 30 日間)
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 件のコメント
Siddart Fredrick
Siddart Fredrick 2019 年 2 月 12 日
編集済み: Siddart Fredrick 2019 年 2 月 12 日
x and f are vectors.
Both x and f are of the same length.
madhan ravi
madhan ravi 2019 年 2 月 12 日
If you illustrate with an example and your desired output it would be clear what you are doing.

サインインしてコメントする。

採用された回答

Kevin Phung
Kevin Phung 2019 年 2 月 12 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by