Calling appdesigner within a function leads to unrecognized function or variable

4 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Andre
Andre el 3 de Mayo de 2022
Editada: Andre el 3 de Mayo de 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

Más respuestas (1)

Benjamin Kraus
Benjamin Kraus el 2 de Mayo de 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 comentario
Andre
Andre el 3 de Mayo de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by