MATLAB 画一个矩形随轨迹运动的动态图,并保留之前每个时刻的矩形框痕迹,大虾帮帮忙
抱歉之前赶着吃饭没看清题目
clc
clear all
close all
x1=0:0.1:2;
y2=1.5:-0.1:0;
x3=2:-0.1:0;
y4=0:0.1:1.5;
y1=1.5*ones(1,length(x1));
x2=2*ones(1,length(y2));
y3=zeros(1,length(x3));
x4=zeros(1,length(y4));
traj_x = -10:0.5:10;
traj_y = traj_x.^2;
x=zeros(length(traj_x),length([x1,x2,x3,x4]));
y=zeros(length(traj_x),length([y1,y2,y3,y4]));
x=traj_x'*ones(1,length([x1,x2,x3,x4]))+ones(length(traj_x),1)*[x1,x2,x3,x4];
y=traj_y'*ones(1,length([y1,y2,y3,y4]))+ones(length(traj_y),1)*[y1,y2,y3,y4];
plot(traj_x,traj_y,'--');%画轨迹如果不需要删掉即可
for i = 1: length(traj_x)
hold on
plot(x(i,:),y(i,:));
axis([-11,15,-0.5,110]);
pause(0.1);
end