How can I pass variable for to m-file when push button is pressed?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have stop button at my GUI and if the stop button is pressed I want to pass a variable to m-file, how can do that? I have stop_flag=0 in m-file, but if stop button is pressed from the GUI then stop_flag should be 1 in m-file.
Teemu
0 个评论
回答(1 个)
Stephen23
2015-9-21
编辑:Stephen23
2015-9-21
Here are the documents showing how to pass arguments between callbacks and functions:
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
If you want an example of this, take a look at my FEX submission cubhelix_view:
This function create a figure with a "demo" button: pressing this turn the demo on and off. It is based on a loop like this:
function chvDemo(tgh,~)
while ishghandle(tgh)&&get(tgh,'Value')
% loop code here
end
end
and is called from the button like this:
uicontrol(figH, 'Style','togglebutton', 'Max',1, 'Min',0, 'Callback',@chvDemo);
2 个评论
Stephen23
2015-9-23
I have never used GUIDE as I prefer to program things myself. I have no idea what is required.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!