1
我想編寫一個命令來顯示機器人位置的方程式及其圖形。這是我的命令,但它並沒有顯示圖表:按情節機器人關節圖的繪圖位置不起作用
clear;
clc;
% initial position
theta1s=-150;
theta2s=-80;
theta3s=-50;
theta4s=-100;
theta5s=-180;
% final position
theta1f=20;
theta2f=100;
theta3f=80;
theta4f=50;
theta5f=180;
% time taken for movement
tf=input('time=')
% acceleration for every link
acc1=(4.*(20-(-150)))./(tf^2)
acc2=(4.*(100-(-80)))./(tf^2)
acc3=(4.*(80-(-50)))./(tf^2)
acc4=(4.*(50-(-100)))./(tf^2)
acc5=(4.*(180-(-180)))./(tf^2)
% blending time for every link
tb1=((0.5.*(tf))-(0.5.*(sqrt((((tf^2).*acc1)-(4.*(20-(-150))))./acc1))))
t = 0;
for x = 0:tf;
t = t + 0.1;
if 0<t<=tb1;
y = theta1s+((0.5.*acc1).*(t^2));
elseif tb1<t<=tf-tb1;
y = (theta1s-((0.5.*acc1).*(tb1^2)))+(acc1.*tb1.*t);
else tf-tb1<t<=tf;
y = theta1s-((0.5.*acc1).*(tf.*t)^2);
end
plot(x,y,'r')
title('Position Versus Time');
xlabel('time in s');
ylabel('position in m');
grid on;
drawnow;
end
disp(y);
感謝您的幫助.. fyi,我使用命令disp(y)顯示y的方程。 例如, y = -150 + 15t^2然後y = -195.21 + 52.08t然後y = 20-15(5-t)^ 2 但它沒有顯示公式,它只是顯示數字。 -149.8640 -149.4560 -148.7760 -147.8240 -146.6000 -145.1040 – 2011-04-16 03:48:21
matlab將y存儲爲向量,但不作爲方程。所以,你不能從y恢復一個方程。如果您無論如何需要顯示它,您可以嘗試將其顯示爲字符串:disp('y = -150 + 15t^2') – user502144 2011-04-16 12:51:04