Button output in GUI

조회 수: 4 (최근 30일)
Zack
Zack 2012년 11월 23일
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.

답변 (2개)

Akiva Gordon
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:

Walter Roberson
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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by