Graphics Programs Reference
In-Depth Information
We encourage you to go back and tinker withthe model (for instance using
a sensitivity parameter that is also inversely proportional to the spacing
between cars) and study the results. We should mention that the To
Workspace block in the lower right has been put in to make it possible to
create a movie of the moving cars. This block sends the car positions to a
variable called carpositions . This variable is what is called a structure
array . To make use of it, you can create a movie withthe following script
M-file:
theta = 0:0.025*pi:2*pi;
for j = 1:length(tout)
plot(cos(carpositions.signals.values(j, :)*2*pi), ...
sin(carpositions.signals.values(j, :)*2*pi), 'o');
axis([-1, 1, -1, 1]);
hold on; plot(cos(theta), sin(theta), 'r'); hold off;
axis equal;
M(j) = getframe;
end
The idea here is that we have taken the circular road to have radius 1 (in
suitableunits),sothatthecommand plot(cos(theta),sin(theta),'r')
draws a red circle (representing the road) in each frame of the movie, and on
top of that the cars are shown with moving little circles. The vector tout is a
list of all the values of t at which the model computes the values of the vector
Search WWH ::




Custom Search