Communication between MATLAB code and GUI

11 次查看(过去 30 天)
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?

采纳的回答

Geoff Hayes
Geoff Hayes 2020-3-30
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 个评论
Miroslav Jiránek
Miroslav Jiránek 2020-3-31
FINALLY its working. Thank you so much for your advices and patience

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by