Wanting to call a number from a 1x6 double
13 views (last 30 days)
Show older comments
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 Comment
Stephen23
on 1 Aug 2022
Edited: Stephen23
on 1 Aug 2022
"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)
Accepted Answer
Dennis
on 1 Aug 2022
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.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!