Effacer les filtres
Effacer les filtres

If statement for a button push in matlab GUI using guide

56 vues (au cours des 30 derniers jours)
Robert le 27 Oct 2016
Hey all Im pretty new at the matlab GUI game. Ive made a few simple ones using the guide before
What I'm up to is the following
I would like to setup a condition that if a button is pushed go do something basically.
My GUI is all setup but I'm not sure how to access the "if the button has been pushed part"
The tag is all setup and the code is running I'm just on the last step if figuring out how to interpret "If a button has been pushed"
Here is the code for the particular button in my gui.m file
I tried just setting the callback == 1 but that did not work. How can i fix this?
function Fast_Right_Button_Tag_Callback(hObject, eventdata, handles)
if Fast_Right_Button_Tag_Callback == 1
Also it appears i have a new issue The guy does not seem to have access to my serial object that is in the workspace. In the code above the serial object is "Motor1"
The gui script is returning the error. undefined variable Motor1
Why can't the guy see a variable in the work space

Réponses (1)

Keerthana Chivukula
Keerthana Chivukula le 4 Nov 2016
I understand that you are trying to execute a piece of code on clicking a button.
In order to do this, we will need to set 'ButtonPushedFcn' property of a button to a callback function handle. This callback function will contain the code that you want to execute on clicking the button.
Refer to the following link to 'Code response to button click':
In the above documentation, we are creating a button, whose 'ButtonPushedFcn' property is set to callback function 'plotButtonPushed'.This function is executed when the button is pushed.
For more information about callbacks, refer to the following link:
To answer your second question, it would be helpful if you can provide more information about the 'run' command that you are using and 'Motor1' argument that is being passed.
(In reference to the link below:
'run' function takes one argument, which is the script name)


En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by