How to access variable from workspace and set it as value of a text box.

2 views (last 30 days)
z = evalin('base', 'z');
numfig = [1];
denfig = [1 0];
sys = tf([numfig],[denfig]);
set(handles.text9, 'String', num2str(z));
set(handles.numtxt, 'String', num2str(numfig));
set(handles.dentxt, 'String', num2str(denfig));

Answers (2)

Stephen23
Stephen23 on 15 Aug 2015
  2 Comments
Harjinder Singh Pabla
Harjinder Singh Pabla on 15 Aug 2015
Edited: Harjinder Singh Pabla on 15 Aug 2015
Hi Stephen, I would like to know how I could get a variable I use on matlab command window which is stored/shown in the workspace window. I was thinking of using global but where do I place it in my GUI's M file?
Walter Roberson
Walter Roberson on 15 Aug 2015
Use guidata() if you are already using the handles structure. For example,
handles.MyVariable = qx17; %where qx17 is the variable to send
guidata(gcf, handles); %update the master copy
then in the routine that needs the value, if the handles structure is already there,
qx17 = handles.MyVariable; %pull out the saved value

Sign in to comment.


Image Analyst
Image Analyst on 15 Aug 2015
You don't need to access the base workspace - I never do. See the FAQ to learn several better methods of sharing variables between your individual functions' workspaces. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

Community Treasure Hunt

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

Start Hunting!