How to click a button of a matlab app programmatically.

169 views (last 30 days)
There is a button named generate random matrix in one of the apps that i am using (unfortunately cannot share it) and i want to be able to perform that function with a command instead of actually clicking with my mouse.
Many thanks in advance.

Answers (2)

Akshay Kumar
Akshay Kumar on 19 Nov 2018
The handle of the button uicontrol object can be obtained using the 'findobj' function with the 'Tag' property. The callback of this handle can be obtained using the 'Callback' property and this can be passed to the 'feval' or 'evalin' functions as arguments to execute the callback.
You can refer to the below MATLAB Answer for more information on how this can be done:
You can also refer to the below link for more information on the properties of uicontrol objects:

Image Analyst
Image Analyst on 19 Nov 2018
You can have the callback function just call a function you wrote, and then you can call it wherever you want, even programmatically within non-callback functions. It's also useful to pass in the handles structure (if you're using GUIDE) so that your function has access to all of the GUI controls' settings/properties.
function btnAnalyze_Callback(hObject, eventdata, handles)
handles = MyFunction(handles); % Simply call a custom function.
function handles = MyFunction(handles)
% Do whatever you want.
Nick Irwin
Nick Irwin on 29 Apr 2022
Thanks for sharing. This worked for me! I was trying to do something similar for automatic clicking on cps test programmatically (one of the client's project). Using this code I was able to automate the clicking and check the clicks per second. Thanks!

Sign in to comment.


Find more on Migrate GUIDE Apps in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by