How do i create a transformation matrix using function?

clear
function t=dh(a,alpha,d,th)
t= [cos(th) -sin(th) 0 a;
sin(th)*cos(alpha) cos(th)*cos(alpha) -sin(alpha) -sin(alpha)*d;
sin(th)*sin(alpha) cos(th)*sin(alpha) cos(alpha) cos(alpha)*d;
0 0 0 1]
end
dh1=dh(10,0,0,pi/4);
I want to create this transformation function which accepts 4 paramters and gives T matrix as output.Pls help.

回答 (1 件)

Mahesh Taparia
Mahesh Taparia 2021 年 1 月 27 日

0 投票

Hi
The function definition in a script is defined at the end of the file or in a separate file. So the below code will work:
clear
dh1=dh(10,0,0,pi/4);
function t=dh(a,alpha,d,th)
t= [cos(th) -sin(th) 0 a;
sin(th)*cos(alpha) cos(th)*cos(alpha) -sin(alpha) -sin(alpha)*d;
sin(th)*sin(alpha) cos(th)*sin(alpha) cos(alpha) cos(alpha)*d;
0 0 0 1]
end

カテゴリ

ヘルプ センター および File ExchangeAcoustics, Noise and Vibration についてさらに検索

質問済み:

2021 年 1 月 21 日

回答済み:

2021 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by