Wanting to call a number from a 1x6 double

조회 수: 12 (최근 30일)
Georgia McGlennon
Georgia McGlennon 2022년 8월 1일
편집: Stephen23 2022년 8월 1일
In my code Im calculating inverse kinematics where:
J = bot.ikine(T, [0 0 0], [1 1 1 1 1 0 0 0]) *180/pi
In the workspace J is labelled as a 1x6 double
and in the command window J outputs 6 different number like so:
J =
9.4623 -71.4600 -21.3836 0.0000 -50.0763 -9.4623
Im trying to print the seperate values on a GUI so for example Theta 1 will display 9.4623, theta 2 will display -71.4600 etc ...
However when I try to select a number from J:
J(1,6)
this displays -9.4623 when I throught it would display 9.4623
also when i then try to select the second number from J:
J(2,6)
I get the following error
Index in position 1 exceeds array bounds (must not exceed 1).
Does anyone have an idea how i can reference to each number within J?
  댓글 수: 1
Stephen23
Stephen23 2022년 8월 1일
편집: Stephen23 2022년 8월 1일
"However when I try to select a number... J(1,6)... this displays -9.4623 when I throught it would display 9.4623"
The sixth value in the first row is -9.4623. You did not explain why you think it should be something else.
"also when i then try to select the second number ...J(2,6) ... I get the following error "
The array J has only one row: what do you expect to occur when you try to access an element from a row that does not exist?
"Does anyone have an idea how i can reference to each number within J?"
Because your data are in a vector, linear indexing is sufficient, e.g.:
J(2)
J(6)

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

채택된 답변

Dennis
Dennis 2022년 8월 1일
Your array has the size 1x6. So it contains values at the positions (1,1) = 9.4623, (1,2) = -71.4600, (1,3) = -21.3836 and so on.
You can either try J(1,1), J(1,2) ... to get your 6 values or J(1), J(2) will also work.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by