How to fire a button/callback in a code generated figure

6 ビュー (過去 30 日間)
Tybault Hollanders
Tybault Hollanders 2017 年 9 月 12 日
コメント済み: Tybault Hollanders 2017 年 9 月 13 日
I want to mimic a click event on a pushbutton in a code generated figure. The code for the button is as followed
u(4) = uicontrol('Parent',figh, ...
'Units', 'normalized', ...
'Position',posbut(4,:), ...
'Tag','Pushbutton4',...
'string','>>',...
'Callback',['global in_callback;', ...
'if isempty(in_callback);in_callback=1;', ...
' try eegplot(''drawp'',4);', ...
' clear global in_callback;', ...
' catch error_struct;', ...
' clear global in_callback;', ...
' error(error_struct);', ...
' end;', ...
'else;return;end;']);%James Desjardins 2013/Jan/22
This is from a toolbox I use. To fire i would need to call the callback, but I can't figure it out.
The way I find this button and its callback is like this:
forwardButton = findall(groot,'Tag','Pushbutton4');
callbackCell= get(forwardButton,'Callback');
from here on I'm quite stuck. I tried thing like str2func, or calling the function in a way like this: callbackCell(callbackCell,[])
Does anyone have an idea on what approach would be more valid to achieve this button click mimic.

採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 13 日
evalin('base', callbackCell)
... but really that code should be re-written to invoke a real function. And the toolbox should probably be rewritten to avoid global variables.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 13 日
It sounds to me as if some graphics objects are set to have handlevisibility 'callback'. Such objects would be found by findall() at any time, but would be found by findobj() only if a callback (any callback) was executing. That was good debugging effort on your part to localize it down to that point.
You can either change the findobj to findall, or you can change the object handlevisibility to 'on', or you could temporarily set the root property ShowHiddenHandles
Tybault Hollanders
Tybault Hollanders 2017 年 9 月 13 日
Yes it was something in that trend. Thank you for the advise, the way it looked for the figure was with the gcf command. This figure was used as a Parent variable in the findobj method. I now find the parent figure with a findobj/findall method and works fine (but a bit slow). Thanks for the advise

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by