AppDesigner, Executing .m files via Pushbutton does not work
古いコメントを表示
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 件のコメント
Mario Malic
2020 年 9 月 27 日
編集済み: Mario Malic
2020 年 9 月 27 日
If you're using assignin, that doesn't mean that called function can use the variable from the workspace. Pass the variables or properties directly in the call of function.
Lukas
2020 年 9 月 27 日
Mario Malic
2020 年 9 月 27 日
function [Output_Arg1, Output_Arg2] = My_Function(Input_Arg1, Input_Arg2)
% ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
% What receives the workspace What My_Function has access to
% that function has been called in
Initialization
Create_ACCCycle
helperACCSetUp
If Initialization generated some values that Create_ACCCycle uses, you're not passing it through
[arg1, arg2] = Initialization
Create_ACCCycle(arg1, arg2)
Otherwise, use properties, create them at the start of code appropriately and you can pass the 'app' as an argument to each function, and within it refer to the properties as
app.Property1
Regarding the error: typo? assigThresh
Lukas
2020 年 9 月 28 日
Mario Malic
2020 年 9 月 28 日
編集済み: Mario Malic
2020 年 9 月 28 日
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!
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!