GUI

5 次查看(过去 30 天)
Abdullah Tahir
Abdullah Tahir 2012-6-4
hi... Can you please tell me how to access GUI (Graphical User Interface) variables in command window? Actually I have declared a button in the GUI and before this button a code runs "a=2" after pressing this button, I want to increment in this variable "a" in the command window. How may I access this variable in command window. Help me, thanks.
  3 个评论
Dmitry
Dmitry 2012-7-11
If you want to get access to variable "a" from workspace in button callback you should declare "a" as global: "global a; a=2;". Then in button callback: "global a; a=a+1"; But if you use GUIDE I suppose you should not use command window, it's inconvenient.
Abdullah Tahir
Abdullah Tahir 2012-7-25
Global does not work here. Global is efficient to access variables in different functions in GUI's m-file. But it is unable to export variables to command window.

请先登录,再进行评论。

采纳的回答

Luffy
Luffy 2012-7-11
编辑:Ned Gulley 2012-7-11
If you want to access data that is in base workspace in your gui functions, use
v = evalin('base','name of variable u want to access');
% the variable's data is now stored in v.
If u want to save data of ur gui work space to base, use
assignin('base','name of variable u want to save','value of variable');

更多回答(1 个)

Caleb
Caleb 2012-7-16
% Intial value of a
a = 2;
setappdata(0,'a',a)
%%%%%%%%%%%%%
setappdata(0,'a',a+1) % Put this part within the callback function of the pushbutton
% Get the value of a
getappdata(0,'a')

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by