problem with gradient- index exceeds matrix dimensions.

Does anyone know what is the problem with the following code? Many thanks.
>> ss=[ 1 9 19 31 45 61 79 99 121 145]; >> t2 = gradient(ss)
and I received error message below: "Index exceeds matrix dimensions."
I checked matlab help file, it says: FX = gradient(F), where F is a vector, returns the one-dimensional numerical gradient of F. Here FX corresponds to ∂F/∂x, the differences in x (horizontal) direction.
So I don't understand why it is not working now.

回答 (2 件)

Guillaume
Guillaume 2015 年 11 月 6 日

1 投票

Most likely you have a variable called gradient, so instead of calling the function gradient you're indexing into the variable. Since the variable has less than 145 elements, you get 'index exceeds matrix dimension'
Don't use matlab function names as variable names.

1 件のコメント

Thorsten
Thorsten 2015 年 11 月 6 日
Use
which gradient
just before gradient(ss) to see what gradient actually is.

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

June
June 2015 年 11 月 6 日

0 投票

Thanks for reminding me. Yes, I am testing someone else's code.

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2015 年 11 月 6 日

コメント済み:

2015 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by