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

6 views (last 30 days)
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.

Answers (1)

Mario Malic
Mario Malic on 6 Dec 2020
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 Comments
Furkan Cakmak
Furkan Cakmak on 6 Dec 2020
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
Mario Malic
Mario Malic on 6 Dec 2020
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.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!