Button output in GUI

3 visualizaciones (últimos 30 días)
Zack
Zack el 23 de Nov. de 2012
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.

Respuestas (2)

Akiva Gordon
Akiva Gordon el 23 de Nov. de 2012
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:

Walter Roberson
Walter Roberson el 23 de Nov. de 2012
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

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by