Wanting to call a number from a 1x6 double

11 vues (au cours des 30 derniers jours)
Georgia McGlennon
Georgia McGlennon le 1 Août 2022
Modifié(e) : Stephen23 le 1 Août 2022
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 commentaire
Stephen23
Stephen23 le 1 Août 2022
Modifié(e) : Stephen23 le 1 Août 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)

Connectez-vous pour commenter.

Réponse acceptée

Dennis
Dennis le 1 Août 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.
  1 commentaire
Georgia McGlennon
Georgia McGlennon le 1 Août 2022
Thank you this has solved the problem!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by