Calling appdesigner within a function leads to unrecognized function or variable

8 views (last 30 days)
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.

Accepted Answer

Andre
Andre on 3 May 2022
Edited: Andre on 3 May 2022
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

More Answers (1)

Benjamin Kraus
Benjamin Kraus on 2 May 2022
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 Comment
Andre
Andre on 3 May 2022
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by