How would you call this function?

1 次查看(过去 30 天)
Crisa Hale
Crisa Hale 2017-12-3
回答: Greg 2017-12-5
function robot_travel(V,w)
%Known Values a,r
%inputs V,w
a=13.5
w=10;%Unknown Value
r=10;%Unknown Value
tht=45;%Degree Theta Inital Rotation
Vr=((2*V)+(w*a))/(2*r);
Vl=((2*V)-(w*a))/(2*r);
xdt=r/2*(Vr+Vl)*cosd(tht);
ydt=r/2*(Vr+Vl)*sind(tht);
thtdt=r/2*(Vr-Vl);%THETA Value Unknown how it effects
axis([-100 100 -100 100])
square=[1 -1 1 -1;-1 1 1 -1];
plot(square(1,:),square(2,:),'*b')
n=50;
xdt=linspace(0,xdt,n);%Increments X and Y so graph can animate
ydt=linspace(0,ydt,n);
for i=1:n
plot(xdt(i)+square(1,:),ydt(i)+square(2,:),'*r')%Plots the change in square postion due to change in x and y
axis([-100 100 -100 100])
pause(.1)
end
hold on
plot(square(1,:),square(2,:),'*b')
hold off
end
I keep getting the following error:
Error using linspace (line 22)
Inputs must be scalars.
Error in robot_travel (line 19)
xdt=linspace(0,xdt,n);%Increments X and Y so graph can animate

回答(1 个)

Greg
Greg 2017-12-5
I didn't analyze for a more efficient solution, but move
xdt=linspace(0,xdt,n);%Increments X and Y so graph can animate
ydt=linspace(0,ydt,n);
inside your loop, and index xdt(i) ydt(i) as elsewhere.

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by