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'')')
end
end
Best Answer