Array indices must be positive integers or logical values.

sigma = 1.0;
Red=double(Red);
NIR=double(NIR);
knr = exp(-(NIR-Red) ^2/(2*sigma ^2));
kNdvi = (1-knr)/(1+knr);
figure,imshow(kNdvi,[]);
colormap(summer);
colorbar;
Error in kNDVI (line 10)
knr = exp(-(NIR-Red) ^2/(2*sigma ^2));

 採用された回答

Image Analyst
Image Analyst 2021 年 8 月 10 日

0 投票

Try
Since NIR and Red are images, not scalar, try
knr = exp(-(NIR-Red) .^ 2 / (2*sigma ^2));
Note that I'm using .^ instead of ^.

1 件のコメント

Simba
Simba 2021 年 8 月 10 日
Yes it finaly worked thank you.

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

その他の回答 (2 件)

the cyclist
the cyclist 2021 年 8 月 9 日
編集済み: the cyclist 2021 年 8 月 9 日

0 投票

Is it possible that you defined a variable called exp? If so, then MATLAB is trying to index into that variable, rather than calling the function. (Never name a variable the same as a MATLAB function.)
If that does not solve your problem, it would be helpful if you uploaded a MAT file and full code required to replicate the error. Otherwise, there is too much guesswork for us.

3 件のコメント

Simba
Simba 2021 年 8 月 9 日
No I didnt declare exp but I am trying to use the function.
I am trying to formulate a code for this formula k(NIR, red ) = exp (  − ​(NIR − red)^2/ (2 σ^2) )
the cyclist
the cyclist 2021 年 8 月 10 日
I won't be able to run your code locally, because I do not have the Image Processing Toolbox. But right now no one can run your code, because we don't have those input files. (It's difficult to tell if the inputs are important.)
Simba
Simba 2021 年 8 月 11 日
thank you for the assistance.

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

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2021 年 8 月 9 日

コメント済み:

2021 年 8 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by