Index in position 2 exceeds array bounds (must not exceed 1)

조회 수: 1 (최근 30일)
Julia Williams
Julia Williams 2019년 7월 30일
댓글: Julia Williams 2019년 7월 30일
x = [(indexbase(1,1)) (indexknuckle1(1,1)) (indexknuckle2(1,3))]
y = [(indexbase(1,2)) (indexknuckle1(1,2)) (indexknuckle2(1,2))]
z =[(indexbase(1,3)) (indexknuckle1(1,3)) (indexknuckle2(1,3))]
scatter3(x,y,z);
indexbase =
-23.5270
69.2678
20.9718
indexknuckle1 =
2.2664
45.3186
92.6306
Anyone know why I am getting this error? I am calling indexbase/knuckle1/2 from workspace variable I have saved. Thanks for any help you can offer!

채택된 답변

Guillaume
Guillaume 2019년 7월 30일
a) get rid of all the unnecessary brackets that make it harder to read your expressions
x = [indexbase(1,1), indexknuckle1(1,1), indexknuckle2(1,3)] %was a 3 meant here for indexknuckle2?
y = [indexbase(1,2), indexknuckle1(1,2), indexknuckle2(1,2)]
z = [indexbase(1,3), indexknuckle1(1,3), indexknuckle2(1,3)]
b) if you're using vectors, then use 1D notation instead of 2D notations, particularly if you're not careful about whether your vectors are row or column vectors:
x = [indexbase(1), indexknuckle1(1), indexknuckle2(3)] %was a 3 meant here for indexknuckle2?
y = [indexbase(2), indexknuckle1(1), indexknuckle2(2)]
z = [indexbase(3), indexknuckle1(3), indexknuckle2(3)]
This will fix your problem.
The cause for the error, is that indexknuckle1(1,2) asks for row 1 column 2 of vectors that have 3 rows and only one column. indexknuckle1(2,1) was meant here, but if you use 1D indexing it works regardless.
  댓글 수: 1
Julia Williams
Julia Williams 2019년 7월 30일
Thank you this worked perfectly! I appreciate the explaination as well!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by