Unable to assign function handle to variable in specified workspace in app App Designer

4 次查看(过去 30 天)
Hi, the issue is about Carrying over variables in app-designer to another function.
The idea is to call (STEP ONE) a figure that designed in app designer from an external function (i,e,TestFunc). The Figure equip with a push button . A new routine is execute whenever the push button is press (STEP TWO). For simplicity, the new routine responsible to assign (STEP THREE) the myVar with a value of 5. Ultimately, I want to assigns (STEP FOUR) the function handle myVar into the workspace of TestFunc using the assign in command. Once succesfully carrying the variable into the caller workspace, the fig will be deleted (STEP FIVE). Then, the NewVar will be assigned (STEP SIX) to equal to NewVar, at the TestFunc environment.
To achieve the following objective, the syntax for the TestFunc and fig of the app designer are;
Syntax of TestFunc
function TestFunc()
%% STEP ONE
fig=app1; % app1 is the name of the figure designed with app designer. With the extension of mlapp
waitfor(fig)
%% STEP SIX
NewVar=myVar;
end
Syntax of fig of the app designer
function ButtonPushed(app, event)
%% STEO TWO
%% Whenever, the pushbutton is pressed, go to this function %%
%% STEP THREE
myVar = 5;
%% STEP FOUR
assignin('caller','myVarX',myVar)
%% STEP FIVE
delete(app)
end %% POINTER ONE
However, MATLAB give the following error;
Unrecognized function or variable 'myVar'.
Error in newt (line 5)
NewVar=myVar;
Upon debugging, I notice myVar has been succesfully transfer to the caller environment just before STEP FIVE. But, at the exit of the ButtonPushed function (POINTER ONE), the myVar at caller environment was cleared.
Appreciate if someone can shed some light to address this problem.

回答(1 个)

Walter Roberson
Walter Roberson 2020-3-6
The "caller" of callbacks is the top level MATLAB session, not the function that created the app.
You will need to find a different approach.
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by