How to click a button of a matlab app programmatically.
67 views (last 30 days)
Show older comments
Hello
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.
0 Comments
Answers (2)
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:
0 Comments
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.
4 Comments
Namita Gera
on 6 Apr 2022
I am struggling with the callback function on buttons and was hoping you could help.
I am creating a game in matlab app designer in which a player plays against the computer opponent. I want to code the CPU to press a button at random when it is its turn. For example, in TicTacToe the player plays against another player but in this case, the opponent is the CPU. The CPU is able to click buttons at random for example if there are 9 buttons it will press on any of those 9 randomly providing it has not been pressed already. I am not sure how to program this any help would be highly appreciated.
This is what i have so far
app.pl_move = 1;
if app.pl_move == 2
n = randi(9)
app.Button_(n).Text = "X";
app.Button_(n).Enable = "off";
app.pl_move = 1;
end
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!
See Also
Categories
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!