Functions calling back function
1 回表示 (過去 30 日間)
古いコメントを表示
The followwing code should shows the value of "a" when the user press the submenue "ADD or "MULT". but it does not. Why?
if true
function mygui5c
%creating the figure
f = figure('visible','on','Position',[350,100,650,500],'color', [0.25,0.83,0.83]);
i_menu = uimenu('Label','My Menu');
op1_menu = uimenu(i_menu,'Label','ADD','callback',{@op1_callback});
op2_menu = uimenu(i_menu,'Label','MULT','callback',{@op2_callback});
global c
global a
c = 0;
if c ==1
a = 10
elseif c ==2
a = 100
end
function op1_callback(hObject,eventdata)
c =1;
mygui5c
end
function op2_callback(hObject,eventdata)
c=2;
end
end
end
0 件のコメント
回答 (1 件)
Andrew Reibold
2013 年 6 月 14 日
編集済み: Andrew Reibold
2013 年 6 月 14 日
Because you set c to zero right before your if/else statements.
c = 0;
Then you say "If c equals 1, then a = 10"
if c ==1
a = 10
This is not true, because c = 0.
And then you say "If thats not true, but c equals 2, then a=100"
elseif c ==2
a = 100
This is also not true, because c does not equal 2... c = 0. You don't have any more 'else' statements so nothing happens and 'a' is never set.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!