필터 지우기
필터 지우기

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