How to click a button of a matlab app programmatically.

76 次查看(过去 30 天)
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.

回答(2 个)

Akshay Kumar
Akshay Kumar 2018-11-19
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 2018-11-19
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 个评论
Namita Gera
Namita Gera 2022-4-6
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
Nick Irwin 2022-4-29
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by