Calling a callback function in GUI
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello to all,
This is my first attempt to generate a GUI. Its aim is to plot the diagrams of variables (saved in .mat file as structure with time). It has to be done by choosing the name of variable from dropdwon list. Below there is a part of a code. I have 2 types of variables sorted into two seperate lists.
ana_dd = uicontrol( 'Style', 'popup',...
'String', ana_vars,...
'Position', [20 340 100 50],...
'Callback', @ploting_ana);
misc_dd = uicontrol( 'Style', 'popup',...
'String', misc_vars,...
'Position', [20 300 100 50],...
'Callback', @ploting_misc);
function ploting_ana(~,~)
val=ana_dd.Value;
plot(T.(ana_vars{val}).time, ...
T.(ana_vars{val}).signals.values);
end
function ploting_misc(~,~)
val=misc_dd.Value;
plot(T.(misc_vars{val}).time, ...
T.(misc_vars{val}).signals.values);
end
As you see both ploting_ana(~,~) and ploting_misc(~,~) are pretty simmilar. There are only differences in the name of variable. I would like to ask if there is a possibility to call and define a callback function in a similar way how in regular function, so I would have sth like below. Then there won't be a need of defining two almost the same functions.
ana_dd = uicontrol( 'Style', 'popup',...
'String', ana_vars,...
'Position', [20 340 100 50],...
'Callback', @ploting(ana_vars));
0 commentaires
Réponse acceptée
Rik
le 12 Mai 2019
Your problem is not taking into account the full potential of callbacks. You throw away the handle to the object you're using. Your function should look something like this. (I would also discourage the use of nested functions, as they make it harder to keep track of your variables)
function ploting_misc(hObject,~)
val=hObject.Value;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!