Matlab create function - Invalid expression

2 vues (au cours des 30 derniers jours)
Mark S
Mark S le 26 Déc 2021
Modifié(e) : Mark S le 8 Jan 2022
Hello,
can someone help me to insert a function in Matlab correctly. I don't know why it doesn't work for me.
I would like to be able to run this function in the command window
Code:
function [relative_pose_endeffector] = forward_kinematics(T_0_3, [0; 0; 0])
q_home = [0; 0; 0;];
q_actual=q_home;
relative_pose_endeffector = double(T_0_3(q_actual(1), q_actual(2),q_actual(3)))
end
In the square brackets I can enter numbers which will be used in the function.
The code already works but I would like to put these "forward kinematics" in a Matlab function. So that I can call this function in the command window.
Can anyone tell me or help me why my function is not working there? Thanks
Here is all my code:
.

Réponse acceptée

Simon Chan
Simon Chan le 26 Déc 2021
Simply modify your function as follows.
function [relative_pose_endeffector] = forward_kinematics(T_0_3, q_actual)
relative_pose_endeffector = double(T_0_3(q_actual(1), q_actual(2),q_actual(3)))
end
  4 commentaires
Stephen23
Stephen23 le 26 Déc 2021
"But when I insert these function now in my command window..."
MATLAB does not permit defining functions in the command window.
Save the function in a file instead.
Mark S
Mark S le 26 Déc 2021
Ok thanks very much for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by