using the values in popup menu function in pushbutton_callback

3 ビュー (過去 30 日間)
Samer Husam
Samer Husam 2012 年 5 月 14 日
Hi; I am doing GUI which has a popup menu that allow the user to choose from several options, lets say I have three options each one has different values for (I,V,P) current, voltage and power. my coding is like this (for example):
function popupmenu1_Callback(hObject, eventdata, handles)
switch get(handles.popupmenu,'Value')
case 1
I=7;
V=20;
p=130;
case 2
I=5;
V=30;
p=170;
otherwise
end
then I need to use these values in some calculation in pushbutton_callback, which it coding as below(for example):
function pushbutton1_Callback(hObject, eventdata, handles)
what code can I use to get these values from the popup menu ?? I need your help please.

採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 5 月 14 日
Hi,
you have two options: either, the popupmenu1_Callback stores the values for I, V, p using e.g. guidata and the pushbutton1_Callback retrieves them. Add at the end of popupmenu_Callback:
handles.data.I = I;
handles.data.V = V;
handles.data.p = p;
guidata(hObject, handles);
and in the pushbutton1_Callback use them:
I = handles.data.I;
Alternative: move the code you've written in popupmenu1_Callback to pushbutton1_Callback, i.e., when you click the pushbutton, the value from the popupmenu is read and the values computed.
Titus
  2 件のコメント
Samer Husam
Samer Husam 2012 年 5 月 15 日
thanks a lot, I will try to apply it and hope its work...
Samer Husam
Samer Husam 2012 年 5 月 15 日
I have tired this way but I couldn't get it.
what did u mean by
guidata(hObject,handles);
I couldn't find such function in my code ?

サインインしてコメントする。

その他の回答 (1 件)

Samer Husam
Samer Husam 2012 年 5 月 17 日
I have tried your both ways, and non of it is working. I can't get the values in push-button.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by