0
我是新來的matlab,我試圖創建一個循環,將生成6矩陣和乘法產生它們(有點像計數器)的所有結果矩陣。你可以看到我的循環波紋管:Matlab在一個循環中乘以矩陣
for i=1:6
A = [ cosd(th(i)) -cosd(alpha(i))*sind(th(i)) sind(alpha(i))*sind(th(i)) L(i)*cosd(th(i)); ...
sind(th(i)) cosd(alpha(i))*cosd(th(i)) -sind(alpha(i))*cosd(th(i)) L(i)*sind(th(i)); ...
0 sind(alpha(i)) cosd(alpha(i)) d(i);...
0 0 0 1];
j = i-1;
fprintf('DH Matrix A%d%d equals to\n', i-1, i);
disp(A);
end
,我想它做的事。如果你想使用循環創建單位矩陣作爲初始值,在循環乘前面的結果有以下
A01 = [ cos(th(1)) -cos(alpha(1))*sin(th(1)) sin(alpha(1))*sin(th(1)) L(1)*cos(th(1)); ...
sin(th(1)) cos(alpha(1))*cos(th(1)) -sin(alpha(1))*cos(th(1)) L(1)*sin(th(1)); ...
0 sin(alpha(1)) cos(alpha(1)) d(1);...
0 0 0 1];
A12 = [ cos(th(2)) -cos(alpha(2))*sin(th(2)) sin(alpha(2))*sin(th(2)) L(2)*cos(th(2)); ...
sin(th(2)) cos(alpha(2))*cos(th(2)) -sin(alpha(2))*cos(th(2)) L(2)*sin(th(2)); ...
0 sin(alpha(2)) cos(alpha(2)) d(2);...
0 0 0 1];
A23 = [ cos(th(3)) -cos(alpha(3))*sin(th(3)) sin(alpha(3))*sin(th(3)) L(3)*cos(th(3)); ...
sin(th(3)) cos(alpha(3))*cos(th(3)) -sin(alpha(3))*cos(th(3)) L(3)*sin(th(3)); ...
0 sin(alpha(3)) cos(alpha(3)) d(3);...
0 0 0 1];
A34 = [ cos(th(4)) -cos(alpha(4))*sin(th(4)) sin(alpha(4))*sin(th(4)) L(4)*cos(th(4)); ...
sin(th(4)) cos(alpha(4))*cos(th(4)) -sin(alpha(4))*cos(th(4)) L(4)*sin(th(4)); ...
0 sin(alpha(4)) cos(alpha(4)) d(4);...
0 0 0 1];
A45 = [ cos(th(5)) -cos(alpha(5))*sin(th(5)) sin(alpha(5))*sin(th(5)) L(5)*cos(th(5)); ...
sin(th(5)) cos(alpha(5))*cos(th(5)) -sin(alpha(5))*cos(th(5)) L(5)*sin(th(5)); ...
0 sin(alpha(5)) cos(alpha(5)) d(5);...
0 0 0 1];
A56 = [ cos(th(6)) -cos(alpha(6))*sin(th(6)) sin(alpha(6))*sin(th(6)) L(6)*cos(th(6)); ...
sin(th(6)) cos(alpha(6))*cos(th(6)) -sin(alpha(6))*cos(th(6)) L(6)*sin(th(6)); ...
0 sin(alpha(6)) cos(alpha(6)) d(6);...
0 0 0 1];
C = A01*A12*A23*A34*A45*A56;
disp(C);