.m Script into GUI App Help
显示 更早的评论
Hi I'm quite new to MATLAB. I'll try my best to explain what I have.
I'm using MATLAB R2020a.
I have an .m file and I want to use this .m in the GUI App. This .m file runs as a short game with user inputs.
I want to make: GUI App with an Image and Start Game button. When the Start Game button is pushed I want it to run my .m file with all user inputs.
How do I make that happen? Plase help me.
4 个评论
Geoff Hayes
2020-6-19
Ann - I think that you would need a callback for your start button that would then call the m file to start the game. Is your m file a script (you do mention script in your question title) or a function? Do you expect it to interact with the GUI in any way?
Image Analyst
2020-6-19
You might check out MAGIC: http://www.mathworks.com/matlabcentral/fileexchange/24224
It used GUIDE. It starts you off with the basic stuff though of course you can add or delete widgets to get the GUI to look like you want it. Or you can use App Designer. Can you use either GUIDE or App Designer to at least create your UI first and then we can look into wiring up the code behind the GUI controls once you have that?
Ann Nguyen
2020-6-19
Ranjan Sonalkar
2020-6-23
Ann
Geoff's answer is the way to do it. Just insert the call to your function in the Game.m file in the Callback script for the Start Game button. If your game needs variables that you set within the GUI, you will need to send them as either input parameters to the Game.m function or as global variable that you declare in the GUI and the Game.m function.
回答(1 个)
Devineni Aslesha
2020-6-23
0 个投票
Hi Ann
- Type guide in MATLAB command window. Open Blank GUI(default).
- Drag and drop the axes and push button in GUI figure window. Save the file with .fig extension.
- A .m file will be opened in MATLAB with the saved filename.
- Add imshow('image.jpg') to gameGUI1_OpeningFcn (Here, gameGUI1 is the filename). Here, the image file should be in the same path where the gameGUI1 file exists.
- Add the .m script which has to be run upon clicking the Start button to pushbutton1_Callback function.
To understand more about GUI, refer the following link
类别
在 帮助中心 和 File Exchange 中查找有关 Desktop 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!