Check if button was pressed in Matlab AppDesigner

46 visualizaciones (últimos 30 días)
Bruno Neto
Bruno Neto el 19 de Sept. de 2022
Comentada: Adam Danz el 19 de Sept. de 2022
Hello I'm developing an app on Matlab AppDesigner and I have several buttons. I want to do a certain code if the button before was pressed and another code if the previous button was not pressed. How can I solve this?

Respuesta aceptada

Adam Danz
Adam Danz el 19 de Sept. de 2022
You've got button A and button B.
When the user presses button B, you want different actions depending on whether button A was already pressed or not, correct?
Follow these steps:
  1. Add a property to your app that stores a logical scalar (1/0) with an initial value of 0 (false) (example of declaring a property)
  2. In the Button A callback function, set the new property to True.
  3. In the Button B callback function, check whether the new property is True of False and act accordingly. Perhaps you'd like to return the property value back to False at the end of the Button B callback function.

Más respuestas (1)

Eric Delgado
Eric Delgado el 19 de Sept. de 2022
Another idea is to use "statebutton" instead "button" to get a more user-friendly GUI. And you can use just one callback to get more code readability. See code attached made on R2021b (if you are working on a different release of Matlab, you have to open App Designer and save the file before run it).

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by