How can I include visuals in this simulation?

조회 수: 2 (최근 30일)
Hussain Hayat
Hussain Hayat 2015년 8월 3일
댓글: Walter Roberson 2017년 7월 10일
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.

답변 (1개)

Madhav Rajan
Madhav Rajan 2015년 8월 5일
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
Walter Roberson
Walter Roberson 2017년 7월 10일
MOHIT comments to Madhav Rajan
this answer is not working
Walter Roberson
Walter Roberson 2017년 7월 10일
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.

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by