Unrecognized function or variable in app designer

11 views (last 30 days)
I would like to run a Matlab script from an App, but i get the error "unrecognized funtion or variable simduration".
In the app, I use 2 buttons. One for assigning values to the base workspace and one to run the script "zwembad_model_app".
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: runsimulationButton
function runsimulationButtonPushed(app, event)
%simout = sim("test_app","StopTime",num2str(app.DurationEditField.Value));
zwembad_model_app
plot(app.UIAxes,simout.watertemperatuur.Time,simout.watertemperatuur.Data);
end
% Button pushed function: SaveParametersButton
function SaveParametersButtonPushed(app, event)
assignin("base","simduration",app.DurationEditField.Value);
assignin("base","lengte",app.lengteEditField.Value);
assignin("base","breedte",app.breedteEditField.Value);
assignin("base","diepte",app.diepteEditField.Value);
assignin("base","start_temperatuur",app.starttemperatuurEditField.Value);
assignin("base","U_bodem",app.U_bodemEditField.Value);
assignin("base","U_wand",app.U_wandEditField.Value);
assignin("base","U_cover",app.U_coverEditField.Value);
assignin("base","opticalefficiency",app.opticalefficiencyEditField.Value);
assignin("base","a1",app.heatlosscoefficientlinearEditField.Value);
assignin("base","a2",app.heatlosscoefficientquadraticEditField.Value);
assignin("base","Ac",app.collectorsurfaceEditField.Value);
assignin("base","serie",app.serieEditField.Value);
assignin("base","parallel_test",app.parallelEditField.Value);
assignin("base","min_temperature_gain",app.mintemperaturegainEditField.Value);
end
end
This is the code from the matlab script (I'm aware that this line of code can be simply integrated in the app code and that works fine but later on I want to expand the script).
simout = sim("test_app","StopTime",num2str(simduration));
When running the app I can see the variables getting stored in de base workspace when the Saveparameters button is activated, but when I press the runsimulation button I get the error. When running the script seperately (after pressing saveparamters button in the app), there is no problem.
I'm not experienced in working with app designer so I hope there is some simple solution I overlooked.
Any help will be appreciated!

Accepted Answer

Mario Malic
Mario Malic on 6 Mar 2021
Hello,
I am not to familiar with Simulink files, but you can try following:
  • If you are able to save the needed variables into .mat file, you can use save and load functions to share the data between App Designer and Simulink. If you run lots of simulations, then second method is faster, it's better in general
  • In your script, get the handles of your app using this answer. This way, you have access to the app and all the components and public properties and methods.
Friendly reminder from all of us here, avoid assignin and similar functions.
  1 Comment
Yari Van Hecke
Yari Van Hecke on 18 Mar 2021
Thank you for your help! As you suggested, I worked around the problem by avoiding the assignin function.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!