If statement for a button push in matlab GUI using guide

37 Ansichten (letzte 30 Tage)
Robert
Robert am 27 Okt. 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
run(Motor1,'f')
pause(.2)
stop(Motor1)
else
stop(Motor1)
end
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

Antworten (1)

Keerthana Chivukula
Keerthana Chivukula am 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':
https://www.mathworks.com/help/matlab/ref/uibutton.html#buimxxx-1
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:
https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-using-the-guide-workflow.html?s_tid=srchtitle#responsive_offcanvas
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:
https://www.mathworks.com/help/matlab/ref/run.html
'run' function takes one argument, which is the script name)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by