AppDesigner, Executing .m files via Pushbutton does not work

14 views (last 30 days)
Hello Community,
I have problems connecting a GUI to MATLAB, especially the base workspace.
I have an App Designer GUI, which executes three .m-files if a pushbutton is pressed.
function INITIALIZEButtonPushed(app, event)
119 Initialization
120 Create_ACCCycle
121 helperACCSetUp
end
That works fine and the variables to be initialized can all be found in my Matlab workspace.
All of them stay there - also until a breakpoint set in line 42 of Create_ACCCycle.m including a variable called controller_type (possible values are [1;2] based on the Adaptive Cruise Control example in Automated Driving Toolbox)
But when in line 42 of my Create_ACCCycle.m code Simulink Model shall be executed a get a weird error from the Pushbutton:
When I initialized all my variables directly in MATLAB everything works fine, only if I execute these scripts via the Pushbutton in the GUI I get this error. I also cannot understand why 'controller_type' does not exist according to the error. As said, at my breakpoint in line 42 so directly before starting my simulink-Model in line 42 the variable 'controller_type' is still set (to 1) in the MATLAB workspace on the right.
Does anyone have an idea why the Pushbutton is still relevant in this case? I mean, In my opinion the pushbutton should have done his job after executing the scripts. The pushbutton mustn't have any logical connection to anything later done in my code.
Error using Create_ACCCycle (line 42)
Error due to multiple causes.
Error in Eingabepanel/INITIALIZEButtonPushed (line 120)
Create_ACCCycle
Caused by:
Error using Create_ACCCycle (line 42)
Variant control 'controller_type == 1' used by block 'ACCWithSensorFusionMdlRef/Adaptive Cruise Controller'
should return a logical value.
Error using Create_ACCCycle (line 42)
Unrecognized function or variable 'controller_type'.
Error using Create_ACCCycle (line 42)
Variable 'controller_type' does not exist.
Error using Create_ACCCycle (line 42)
Variant control 'controller_type == 2' used by block 'ACCWithSensorFusionMdlRef/Adaptive Cruise Controller'
should return a logical value.
Error using Create_ACCCycle (line 42)
Unrecognized function or variable 'controller_type'.
Error using Create_ACCCycle (line 42)
Variable 'controller_type' does not exist.
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 382)
Error while evaluating Button PrivateButtonPushedFcn.
  6 Comments
Lukas
Lukas on 28 Sep 2020
I guess I meanwhile have found what I was looking for:
evalin('base', 'name_of_script')
https://www.mathworks.com/matlabcentral/answers/270019-how-do-i-run-a-script-from-a-gui-that-will-run-in-the-base-workspace
Mario Malic
Mario Malic on 28 Sep 2020
Edited: Mario Malic on 28 Sep 2020
You can generate property without specifying its type.
properties (Access = public)
X
Y
end
In the first post, you were missing a controller_type variable, which is variable from initialization function that Create_ACCCycle does not have access to. You can set it as a property and refer to it as mentioned above to check whether is that the only thing shared between functions.
You don't have to pass everything, just what the function needs. I prefer to work with properties, since you don't have to worry a lot. Otherwise, a typical approach would be
controller_type = Initialization
Create_ACCCycle(controller_type) % and so on
Edit: I forgot to mention that I did not work with Simulink.
Great find on the solution!

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!