Calling appdesigner within a function leads to unrecognized function or variable

조회 수: 2 (최근 30일)
Hello everyone,
I am desperately looking for a solution. I call up an app within a function. The variables are created within the function and passed as input to the app.
function RunSim(A,B)
% Parameter
TestCase = 'TBD';
Date = 'TBD';
% Call App
App_Example = App_Name(TestCase,Date)
waitfor(App_Example)
% I need A,B,TestCase,Date for the further calculations within this function.
end
The next step are adjustments made via the GUI and these adjustments are loaded back into the workspace from the function. As I have a refresh button, I want to reload the list after the change has been made.
function startupFcn(app,TestCase,Date)
%% Read List_TestCases.xlsx
% The values can be modified in the excel TestCases.xlsx
% Expand List_TestCase
if length(TestCase(1,:)) < 6
TestCase(1,6) = {'ID'};
%Transfer to function workspace
assignin("caller","temp",List_TestCases);
evalin("caller","List_TestCases = temp;");
end
TestCase = evalin("caller","TestCase;"); % Unrecognized function or variable 'TestCase'.
end
Here the error occurs that during the refresh, when the function startupFcn is executed again, the variable can no longer be found. Unfortunately I can't find a solution, it works if the app is not accessed within a function (direct via script), but I have to access the app within this function.
I thank you in advance.

채택된 답변

Andre
Andre 2022년 5월 3일
편집: Andre 2022년 5월 3일
All necessary parameters have to be transferred to the basic workspace in order to allow the app to access to these parameters. When the app is closed, the parameters will be deleted from the basic workspace.
function RunSim(A,B)
% Parameter
TestCase = 'TBD';
Date = 'TBD';
% Transfer necessary parameter to base workspace
assignin("base","TestCase",TestCase);
assignin("base","Date",Date);
% Call App
App_Example = App_Name(TestCase,Date)
waitfor(App_Example)
% Transfer Results to function (caller) workspace
TestCase = evalin("base","TestCase");
METADATA = evalin("base","METADATA"); % Parameter generated in App and is needed withing the function
% Clear all parameter from base workspace
evalin("base","clear TestCase METADATA");
end

추가 답변 (1개)

Benjamin Kraus
Benjamin Kraus 2022년 5월 2일
There is no straightforward way to assign outputs from an App Designer app. I found a few other discussions on this topic on MATLAB Answers already:
The second one has some workarounds that might satisfy your needs.
  댓글 수: 1
Andre
Andre 2022년 5월 3일
Thank you for your comment, I have found a workaround. I assigne all for the app necessary parameters to base worksoace and delete them again when the app is closed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by