Mapping MATLAB workspace variable in 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?

+3
source share
2 answers

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

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

, , , . GUI :

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
+5

SETAPPDATA ( ) GETAPPDATA ( GUI).

someMatrix

setappdata(0,'someMatrix',someMatrix) % in the main workspace

someMatrix = getappdata(0,'someMatrix') % in GUI
+1

Source: https://habr.com/ru/post/1762655/


All Articles