I am animating a road which will be used in the analysis of a half car suspension model. At the moment the plot follows the road as it is being generated. What I want to do is plot the car in the middle of the plot and pull the road from right to left underneath the car.
for t = 1:200
r = road(t);
R(t,:) = r;
% pause(.05)
set(line,'YData',R); %# Update the y data of the line
drawnow %# Force the graphics to update immediately
ylim([-1 1])
xlim([t-5 t+5])
end
figure; plot(R,'k');
ylim([-1 1])
Does anyone have any suggestions on how to, rather than follow the road, have it come across the figure. Any help is much appreciated.

댓글 수: 1

James Murphy
James Murphy 2016년 4월 26일
The road function is as follows,
function [x] = road(t)
% ROAD takes in time t and outputs height x.
% road produces a step at t = 50s, undulation at t=100 and random road at
% t>150.
if t < 50
x = 0;
return
elseif t >=50 && t < 100
x = 0.05;
return
elseif t>=100 && t<150
% x = 0.05 + 0.025*(0.4*sin(t));
% x = (.05*sin(f*[1:.1:126]))+.05;
x = 0.05*sin(0.25*t) + 0.05;
return
else
x = 0.05 + 0.025*rand(1);
return
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

질문:

2016년 4월 26일

댓글:

2016년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by