フィルターのクリア

Get value of a variable from one popupmenu1 function and use it in different popmenu2 function

1 回表示 (過去 30 日間)
Hi; I am doing GUI which has two popup menu functions.
I defined the value of a variable x in popupmenu1 function. and want to use the value of x in popupmenu2. plz anybody tell me how can i use this??
For example->
function popupmenu1_Callback(hObject, eventdata, handles)
b=get(handles.popupmenu1, 'value');
switch b
case 1
x=0:.1:1;
case 2
x=0:.1:10;
case 3
x=0:.1:100;
end
function popupmenu2_Callback(hObject, eventdata, handles)
[In this function, I want to use the value of x.]

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 5 月 29 日
You cannot do that as-is. "x" is local to the workspace of popupmenu1_Callback and will disappear as soon as that callback finishes. You need to save the value of x in a place that the other callback can get at it.
  1 件のコメント
Sanjay Agrawal
Sanjay Agrawal 2013 年 5 月 29 日
Thanx Walter for your reply. But I found out the solution. Here is the code, may be helpful for you.
function popupmenu1_Callback(hObject, eventdata, handles) b=get(handles.popupmenu1, 'value'); switch b case 1 x=0:.1:1; case 2 x=0:.1:10; case 3 x=0:.1:100; end handles.x=x guidata(hObject,handles) In the second callback
function popupmenu2_Callback(hObject, eventdata, handles) x=handles.x

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by