Why am I unable to open a variable using OPENVAR from a GUI callback in the Array Editor?

3 views (last 30 days)
I am trying to open a variable using the function OPENVAR from a UI control callback in my GUI. The variable exists within the scope of the callback. The Array Editor opens but returns the following statement:
The variable x does not exist.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is expected behavior. OPENVAR opens variables that live in the current workspace, and updates itself as the workspace changes. Variables that exist in 'alternate' workspaces (such as callback workspaces) are only accessible as long as that alternate workspace remains in scope (current workspace). By default, the 'base' workspace is in scope during regular execution of the callback. The callback workspace comes into scope when the program is executed in debug mode.
As a workaround, use debug mode to ensure that the callback workspace remains in scope when OPENVAR is called.
You can also use the EVALIN function along with the OPENVAR function in the callback of the uicontrol to open the base workspace variable in the array editor from the GUI. Here is a simple example that shows how this can be implemented.
function UI_test
uicontrol('style','pushbutton', 'callback',@clbk)
function clbk(source,eventdata)
evalin('base','openvar(''X'')') % X being a variable in the base workspace
end
end

More Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!