Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display of MATLAB workspace variable into GUI function

I have a variable in the MATLAB workspace and I want to pass this variable to a function in my GUI.

How do I achieve this task?

like image 608
Muhammad wasif Avatar asked Jan 28 '26 13:01

Muhammad wasif


1 Answers

You can use the function EVALIN in your GUI to get the value of a variable from the base workspace. The following example extracts the value of the variable A in the base workspace and places that value in the local variable B:

B = evalin('base','A');

You could, for example, have an editable text box in your GUI that allows the user to enter the name of a variable to import from the base workspace. One of your GUI functions could then read the string from the editable text box and attempt to fetch that variable from the base workspace to use in some computation:

varName = get(hEditText,'String');    %# Get the string value from the uicontrol
                                      %#   object with handle hEditText
try                                   %# Make an attempt to...
  varValue = evalin('base',varName);  %#   get the value from the base workspace
catch exception                       %# Catch the exception if the above fails
  error(['Variable ''' varName ...    %# Throw an error
         ''' doesn''t exist in workspace.']);
end
like image 194
gnovice Avatar answered Jan 30 '26 05:01

gnovice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!