Index in position 1 is invalid. Array indices must be positive integers or logical values. getting this error command while running this code

2 ビュー (過去 30 日間)
old_obs_1 = plot3(Obs5(1,1), Obs5(1,2), Z(round(Obs5(1,2)),round(Obs5(1,1))),'o','MarkerSize',20, 'MarkerFaceColor','r','MarkerEdgeColor', 'k');
Please help
Thanks in advance
  2 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 2 月 2 日
Please provide the definitions of Obs5 and Z.
JIBIN GEORGE
JIBIN GEORGE 2022 年 2 月 2 日
It is already defined while evaluating the code as a whole

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

採用された回答

Simon Chan
Simon Chan 2022 年 2 月 2 日
At least the value on Obs5(1,2) is <0.5
Obs5 = [0.5 0.4];
Z=rand(2,3);
old_obs_1 = plot3(Obs5(1,1), Obs5(1,2), Z(round(Obs5(1,2)),round(Obs5(1,1))),'o','MarkerSize',20, 'MarkerFaceColor','r','MarkerEdgeColor', 'k');
Index in position 1 is invalid. Array indices must be positive integers or logical values.
  1 件のコメント
JIBIN GEORGE
JIBIN GEORGE 2022 年 2 月 2 日
Yes my previous defenition of the Obs5 = [125 0];
when it changed to Obs5 = [125 10];
works fine
Thank you

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

その他の回答 (1 件)

KSSV
KSSV 2022 年 2 月 2 日
This error is simple, you are trying to extract more number of elements than present in the array.
A = rand ; % A is aconstat i.e 1x1 array.
A(1) % no error
ans = 0.6042
A(1,2) % error becasue there is no second element, alse A(2) means the same
Index in position 2 exceeds array bounds. Index must not exceed 1.
Check your variable dimensions. You have used index 2, it seemsthere is no second element.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by