While loop not working in MATLAB app designer callback function

Hello there,
I making a simple app that reads numerical data inputed by the user and outputs arrays of data as result of some formula. In one of the callback functions, I have a while loop which, after the conditions is fulfilled, gives an array as a result. The function works correctly in the editor but in the app designer, it fails to recognise all the variables that are in the while loop.
Can anyone suggest what would be the possible reason behind this?
Thanks

답변 (1개)

Jon
Jon 2020년 10월 2일
편집: Jon 2020년 10월 2일

0 개 추천

You probably have a scoping issue. Shared values are typically stored variable names such as app.myVariable
To give any more specific help you would need to provide the code you are using and the detailed error messages that you are receiving

댓글 수: 7

hey Jon, thanks for getting back. I have attached the code now. Also, below is the code in the callback in the app designer looks and error message:
--
% All inputs from the user
K_FAW = app.CoilStiffness1NmmEditField.Value;
W_FAW = app.UnladenloadperwheelkgEditField.Value;
MR_FAW = app.Motionratio1EditField.Value;
BST_FAW = app.UnladentoBStouchtravel1mmEditField.Value; %unladen to bump stop touch travel
WCC_FAW = app.InitialwheelcentrecoordinateEditField.Value; % inital wheel centre position
[WT_FAW,Total_BSLoad_FAW,Total_Load_FAW] = WheelTravelFAW(K_FAW,W_FAW,MR_FAW,BST_FAW);
-----
Error message:
Error using WheelTravelFAW
Too many input arguments.
Error in NewTemplate/CreateSpringingDataButtonPushed (line 121)
[WT_FAW,Total_BSLoad_FAW,Total_Load_FAW] = WheelTravelFAW(K_FAW,W_FAW,MR_FAW,BST_FAW,4000,9.81);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 386)
Error while evaluating Button PrivateButtonPushedFcn.
Jon
Jon 2020년 10월 2일
편집: Jon 2020년 10월 2일
Callback functions in the app designer must alway have app and event as their first two arguments
Actually I think these are the only arguments that the app designer callbacks can have. If you want to pass any data to them then put it into the app properties so you can access it inside of the callback function. Note in the appdesigner code view you can add properties using the property tab in the code browser (on the left side of the screen)
Hi, sorry if this wasn't clear earlier. But this isn't a callback function. The function that I shared is within a button pushed callback function in the app. Below is a screenshot of the callback function.
Where is this function call made (I cut an pasted this from your error message above)?
Error in NewTemplate/CreateSpringingDataButtonPushed (line 121)
[WT_FAW,Total_BSLoad_FAW,Total_Load_FAW] = WheelTravelFAW(K_FAW,W_FAW,MR_FAW,BST_FAW,4000,9.81);
Note that it has 6 input arguments and your definition of WheelTravelFAW only has 4 input arguments. This is what is giving you the error. You need to find out where this call is coming from and fix it. From the error message. It looks like it comes from a function call CreateSpringingDataButtonPushed
Please ignore that I have already corrected that but it still fails to recognise y_FAW basically the outcome of the while loop.
If you need more help please post the full error message you are now getting and even better attach enough code to reproduce the problem

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 10월 2일

댓글:

Jon
2020년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by