Borrar filtros
Borrar filtros

How to click a button of a matlab app programmatically.

85 visualizaciones (últimos 30 días)
Erinton Konomis
Erinton Konomis el 5 de Nov. de 2018
Comentada: Nick Irwin el 29 de Abr. de 2022
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.

Respuestas (2)

Akshay Kumar
Akshay Kumar el 19 de Nov. de 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 el 19 de Nov. de 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 comentarios
Namita Gera
Namita Gera el 6 de Abr. de 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
Nick Irwin el 29 de Abr. de 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!

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by