Azzera filtri
Azzera filtri

How can I include visuals in this simulation?

3 visualizzazioni (ultimi 30 giorni)
Hussain Hayat
Hussain Hayat il 3 Ago 2015
Commentato: Walter Roberson il 10 Lug 2017
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.

Risposte (1)

Madhav Rajan
Madhav Rajan il 5 Ago 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 Commenti
Walter Roberson
Walter Roberson il 10 Lug 2017
MOHIT comments to Madhav Rajan
this answer is not working
Walter Roberson
Walter Roberson il 10 Lug 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.

Accedi per commentare.

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by