Functions calling back function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Andrew Reibold
le 14 Juin 2013
Modifié(e) : Andrew Reibold
le 14 Juin 2013
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 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!