How can I invoke a State button without pressing it manually, but doing it programatically?

Hello,
I have been trying to invoke the state button callback in my program by pushing another button (push button). For example, lets say that I have provided one state button (or check box button: does not matter) and one push button. When user press the state button, some actions are taken in the program. However, I want to do this by not using the "State button" but by using the "push button", i.e. same actions are taken when "push button" is pushed.
I can trigger another "push button" using another "push button" but, when it comes to the callbacks which requires "event", I could not achieve that.
Any help is greatly appreciated.

답변 (1개)

Hello,
To my slim knowledge, I wouldn't recommend it to run another callback within one. It could be better if you would wrap the code from the state button callback into a function that you'd call within other callbacks.
Current state
function CallbackFcn1(src, event)
%some code
end
function CallbackFcn2(src, event)
%some code as well
end
Wrap your code like this
function HelperFcn()
%some code
end
function CallbackFcn1(src, event)
HelperFcn()
end
function CallbackFcn2(src, event)
%some code as well
HelperFcn()
Make sure you change state value to true either within HelperFcn
or in body of this function
end

댓글 수: 2

Why should I do this?
the code under the callback functions are quite complicated. So I do not want to repeat the code? Cant i invoke a callback using other callback?
Thanks
I am saying that that complicated code within a callback, put it in a function, and call it that way. You replace the body of the callback with a single line which calls the function.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2020년 12월 6일

댓글:

2020년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by