How to call callback the code through the selection of push button

Hallo, I am building a GUI. I have used a popupmenu button with two options, for example(a,b). How can i callback the code which i have written in the random pushbutton_x when i select case "a" in my push button. Thanks.
Regards, Anush

4 commentaires

What is a "popupmenu button"? Eitehr it is a popup menu or a button. "example(a,b)" is not clear also. What is "the random pushbutton_x"?
Hello jan, I am reading a data from a .xls file and making some calculations. This calculations i am doing it under a pushbutton1_callback. Similarly i have a different set of calculations in the same pushbutton1_callback. Finally Now i am interested in performing this set of calculation with the use of popupmenu_callback for an example if i select case "a" and press my pushbutton1 certain set of calculation has to perform. if i select case "b" and press my pushbutton1 the other set. I am having trouble with calling this pushbutton1_callback with reference to my popupmenu's which i select.
Please explain the sentence "I am having trouble with calling this pushbutton1_callback with reference to my popupmenu's which i select." Include the code and mention, what trouble you have. Otherwise giving an answer is based on guessing only.
% --- Executes on selection change in popupmenu.
selectedIndex = get(handles.popupmenu, 'value');
% Take action based upon selection
if (selectedIndex == 1);
%%%%%%How to call the push button operation here ?? %%%%%%%%
else if (selectedIndex == 2);
% pushbutton_Callback;
h = msgbox('Operation Completed');
end
% --- Executes on button press in pushbutton.
function pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f = figure;
data = xlsread('abc.xlsm','Data','C7:F23');
t = uitable(f);
display(data);

Connectez-vous pour commenter.

 Réponse acceptée

When a popup menu entry is selected, the callback of this uicontrol is called. You do not define a callback for the contents of the menu, but for the menu object only. The distinction of different code branches has to be implemented in the callback:
function popupmenuCB(hObject, EventData)
handles = guidata(hObject);
String = get(hObject, 'String');
Value = get(hObject, 'Value');
Selected = String{Value};
switch Selected
case 'a'
...
case 'b'
...
otherwise % No CASE without OTHERWISE
error('Unexpected switch')
end

Plus de réponses (1)

Jan
Jan le 18 Mai 2017
Modifié(e) : Jan le 18 Mai 2017
After your comment: This is no valid Matlab syntax:
if (selectedIndex == 1);
else if (selectedIndex == 2);
h = msgbox('Operation Completed');
end
Either an "end" is missing, or you have to remove the space:
elseif (selectedIndex == 2);
% not: else if (selectedIndex == 2);
For: "How to call the push button operation here ??" Simply by calling the pushbutton callback:
pushbutton_Callback(hObject, eventdata, handles)
It is not used here, but adjusting the data might be better:
pushbutton_Callback(handles.pushbutton1, eventdata, handles)
or how your button is called in the struct. Use the debugger to determine this.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Question posée :

le 15 Mai 2017

Modifié(e) :

Jan
le 18 Mai 2017

Community Treasure Hunt

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

Start Hunting!

Translated by