How can I include visuals in this simulation?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So the attached files include code for a traffic simulation. How can I make this visual? I want something like a traffic signal on a road and instead of the stars that are in this programs output I want to include image like some sort of clip art. So basically a road with the cars appearing and disappearing. How can I make this work? If you can include some helpful tutorials or links Id be grateful.
0 comentarios
Respuestas (1)
Madhav Rajan
el 5 de Ag. de 2015
I understand that you want to visualize the traffic with some clip art images. A sample function "draw.m" is attached which takes the number of cars as input and places that many cars on the road. The script uses an image for the road and an image for the car and calls the "image" and "imshow" functions to render the images. To update the visualization at each timestep, make a call to the "draw" function that is provided and pass the argument 'CARS' before ending the for loop in the 'traffic.m' file.
You can extend this function to create images for your signals and manipulate them if they are red and green.
I have also attached the sample road and car images that I have used in the sample 'draw' function. You can refer the following link for more information on "drawnow" and how to use it for animation:
Hope this helps.
5 comentarios
Walter Roberson
el 10 de Jul. de 2017
If the imshow() is giving an error then you might be using an older version of MATLAB in which imshow() was part of the Image Processing Toolbox; in that case, change imshow() to image() as Madhav Rajan indicated.
Another possibility is that you might not have road.jpg available in the current directory or a directory that is on your MATLAB path.
The code given relies upon R2014b or later. If you are using an earlier MATLAB then it would need some modification; please indicate the target version of MATLAB in that case.
Ver también
Categorías
Más información sobre Display Image en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!