Button output in GUI
1 次查看(过去 30 天)
显示 更早的评论
I am want to know if it is possible to have a button include an output as well as a callback function. I am creating an apples to apples game in matlab for a programing project. I want to display seven cards on buttons for a user to chose one from. I then want to store that choice along with the choice of other users playing the game. Because each button is just a different choice, I was wondering if it was possible to have all the buttons on the screen to have the same call back function and then have the callback function determine which choice was selected and save it to a cell array before proceeding on to the next player.
0 个评论
回答(2 个)
Akiva Gordon
2012-11-23
It seems like having all of the buttons share a callback is a good idea for this situation.
One good way to share data between callbacks is by using the functions GETAPPDATA and SETAPPDATA. Check out the doc for these functions:
Also, you may want to check out this video:
0 个评论
Walter Roberson
2012-11-23
Only a few kinds of callback functions can have outputs, such as PostAction callbacks upon resizing images. Callback functions for uicontrols cannot have outputs.
It is quite legal for a number of different uicontrol to use the same callback. Exactly which control was activated can be determined by comparing the handles of the hObject passed in, or by examining the tag of that object, or by storing information in UserData, or the like.
You do not need the callbacks to have outputs to change data that is held in common. See http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!