Communication between MATLAB code and GUI

3 vues (au cours des 30 derniers jours)
Miroslav Jiránek
Miroslav Jiránek le 30 Mar 2020
Commenté : Geoff Hayes le 31 Mar 2020
Hello all,
Maybe I have very simple question, but I can't find out how to start communicate my programme in MATLAB with GUI. GUI looks like this. I placed the background image of the crossroad in GUI, where the whole simulation should run
function background_CreateFcn(hObject, eventdata, handles)
bg = imread('C:\Users\Miroslav\Desktop\Crossroad\cross_matl.png'); imagesc(bg);
uistack(bg, 'bottom');
At the beginning of the matlab program, I initialize the images of cars which has to be moved on the crossroad in GUI.
openfig('C:\Users\Miroslav\Desktop\Crossroad\GUI_final.fig'); %opening GUI
hold on
%----------------------DOWN -> UP --------------------------------------
car_9=imread('C:\Users\Miroslav\Desktop\Crossroad\blue_car.png');
car_10=imread('C:\Users\Miroslav\Desktop\Crossroad\red_car.png');
car_11=imread('C:\Users\Miroslav\Desktop\Crossroad\white_car.png');
car_12=imread('C:\Users\Miroslav\Desktop\Crossroad\yellow_car.png');
CAR_9 = Move_DU(); %deklaration objects to the class
CAR_10 = Move_DU();
CAR_11 = Move_DU();
CAR_12 = Move_DU();
DU = [CAR_9,CAR_10,CAR_11,CAR_12];
car_9_img = imagesc('CData',car_9,'XData',DU(1).getCurrentX(),'YData',DU(1).getCurrentY()); %loading images GUI
car_10_img = imagesc('CData',car_10,'XData',DU(2).getCurrentX(),'YData',DU(2).getCurrentY());
car_11_img = imagesc('CData',car_11,'XData',DU(3).getCurrentX(),'YData',DU(3).getCurrentY());
car_12_img = imagesc('CData',car_12,'XData',DU(4).getCurrentX(),'YData',DU(4).getCurrentY());
du = [car_9_img,car_10_img,car_11_img,car_12_img];
But when I start the program, images of cars makes their own figure, where they start moving
So.. My question is. How to plot images of cars on the background in the GUI?

Réponse acceptée

Geoff Hayes
Geoff Hayes le 30 Mar 2020
Miroslav - is the "only" difference between https://www.mathworks.com/matlabcentral/answers/511717-image-rendering-in-gui and this question is that your crossroads is now a background image? If so, why not create an axes in your GUI where you place the crossroads image and then use that same axes to add the cars? (In a similar fashion as to what you did in the other question.)
  10 commentaires
Miroslav Jiránek
Miroslav Jiránek le 31 Mar 2020
FINALLY its working. Thank you so much for your advices and patience
Geoff Hayes
Geoff Hayes le 31 Mar 2020
No problem! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by