Matlab create function - Invalid expression

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:
.

 채택된 답변

Simon Chan
Simon Chan 2021년 12월 26일

0 개 추천

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

Mark S
Mark S 2021년 12월 26일
Ok thanks it worked. But when I insert these function now in my command window: forward_kinematics(T_0_3, q_actual - I get the error: Unrecognized function or variable 'forward_kinematics'. Because it should be possible that I can insert this function in the command window... Or can I use the function only inside of the script and not in the command window?
Simon Chan
Simon Chan 2021년 12월 26일
You may try to save this function separately as forward_kinematics.m and put into your working folder.
Attached please find the file.
Stephen23
Stephen23 2021년 12월 26일
"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 2021년 12월 26일
Ok thanks very much for your help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2021년 12월 26일

편집:

2022년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by