If statement for a button push in matlab GUI using guide

50 ビュー (過去 30 日間)
Robert
Robert 2016 年 10 月 27 日
回答済み: Keerthana Chivukula 2016 年 11 月 4 日
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

回答 (1 件)

Keerthana Chivukula
Keerthana Chivukula 2016 年 11 月 4 日
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)

カテゴリ

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by