Image rendering in GUI
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Miroslav Jiránek
am 19 Mär. 2020
Kommentiert: Geoff Hayes
am 19 Mär. 2020
Hello all. I have a problem with rendering my image in GUI. I'm trying to creat a automatic simulation of crossroad with traffic lights. First of all I need to move with cars, which I load as a image to GUI. The problem is that when the for loop starts rendering image of the car(Image number 1), it does not delete the former images which is unacceptable (image number 2). Can anyone help me with this, please?
clc
clear
I=imread('C:\Users\Miroslav\Desktop\Crossroad\cross_matl.png');
hi = imagesc(I)
hold on
car=imread('C:\Users\Miroslav\Desktop\Crossroad\blue_car3.png');
Nt=10; % Number of time steps
xval=450;
ymin=900;
ymax=-75;
y=linspace(ymin,ymax,Nt);
for it=1:Nt
imagesc('CData',car,'XData',[450],'YData',[y(it)])
pause(1);
end
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 19 Mär. 2020
Miroslav - rather than creating a new image (position) for the car on each iteration of the loop, try updating the YData (vertical position) for the car. For example,
Nt=10; % Number of time steps
xval=450;
ymin=900;
ymax=-75;
y=linspace(ymin,ymax,Nt);
hCar = imagesc('CData',car,'XData',[450],'YData',[y(1)])
for it=1:Nt
set(hCar,'YData',[y(it)]);
pause(1);
end
I haven't tried the above but I think it could work.
8 Kommentare
Geoff Hayes
am 19 Mär. 2020
But y is a 1x16 (or 16x1) array and hCars is a scalar (1x1)
y=linspace(ymin,ymax,Nt);
hCars = imagesc('CData',car,'XData',[450],'YData',[y(1)]) %start location
so the error message makes sense. You will need to determine the x and y for each of the sixteen cars (presumably half the cars are going east-west (or west-east) and so the y is fixed but the x is variable) and you will need to create a handle to each car image for each of the sixteen cars. If we just concentrate on the cars going north-south (or south-north), at iteration 1, what is the y position for each of the cars? What should the y position/coordinate be on the second iteration? Do the cars follow the other? Do they go the same speed?
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!