Calling a callback function in GUI
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Rik
2019 年 5 月 12 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!