Error using a function in App Designer, not returning the correct value.

조회 수: 5 (최근 30일)
George Fryda
George Fryda 2019년 11월 1일
댓글: Jyotsna Talluri 2019년 11월 7일
I am attempting to create an fsolve function inside of an app in the App Designer tool.
methods (Access = private)
function Deceleration = SolveForDecel(~,UTF,HB,HT,L,LB,LT,WC,WT,PHI,CHI,PSI,PSIT)
fun = @(x) x*(1+PHI)*(1+WC/(WC+WT))/((1-PSI+x*CHI)-(WC/(WC-WT))*((1-PSIT)*LB/L+x*((HT/LT-HB/LT)*LB/L-HB/L)))-UTF;
x = fzero(fun,.1);
Deceleration = x;
end
end
methods (Access = private)
% Callback function: SolveforDecelerationButton, UIFigure
function UIFigureKeyPress(app, event)
valuefordecel = SolveForDecel(app,app.TireRoadfrictioncoefficientEditField.Value, ...
app.GroundhitchballEditField.Value, ...
app.GroundcgtrailerEditField.Value, ...
app.WheelbaseofcarEditField.Value, ...
app.RearaxlecarhitchballEditField.Value, ...
app.TraileraxlehitchballEditField.Value, ...
app.WeightofcarEditField.Value, ...
app.WeightoftrailerEditField.Value, ...
app.RearbrakeFtotalbrakeFEditField.Value, ...
app.cgheightcarwheelbaseEditField.Value, ...
app.rearaxlenotrailerweightEditField.Value, ...
app.rearaxletrailerweightEditField.Value);
app.DecelerationofCombinationEditField.Value = valuefordecel;
I believe the event is being triggered, and then it runs into an issue in the Fsolve (these are the outputs):
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at -1.15052e+308 is NaN.)
Check function or try again with a different starting value.
Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 185)
'Value' must be a double scalar within the range of 'Limits'.
Error in Trailer_Dynamic_Simulation_Model/UIFigureKeyPress (line 79)
app.DecelerationofCombinationEditField.Value = valuefordecel;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
I am at a loss to determine exactly what the solution is. When I manually run through the function in the command window with realistic values it solves to .3014, which makes sense.
The error it is reading out in App Designer is:
  댓글 수: 3
George Fryda
George Fryda 2019년 11월 4일
Of course. It won't let me attach the App file, it doesn't support .mlapps, but realistic values may be seen here:
matlab realistic values.PNG
In particular, these are the values that fed correctly into the function when i did it in the command vindow, and worked - giving x as [.3014].
(Chi needed to be CHI)
Guillaume
Guillaume 2019년 11월 6일
What are the values of the inputs that trigger the error?

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

답변 (1개)

Jyotsna Talluri
Jyotsna Talluri 2019년 11월 6일
Hi,
The possible cause of error may be because of using 'Edit Field(Text)' instead of 'Edit Field (Numeric)'.Make sure you are using the 'Edit Field(Numeric)'.It worked for me when I reproduced it with your given inputs and equation as shown in the attched figure
  댓글 수: 2
George Fryda
George Fryda 2019년 11월 6일
Thank you for the suggestions Jyotsna,
I cannot find exactly where this would be in the code. In the place where the inputs are being declared appears to already specify that they are numeric.
% Create GroundcgtrailerEditField
app.GroundcgtrailerEditField = uieditfield(app.UIFigure, 'numeric');
app.GroundcgtrailerEditField.Limits = [0 Inf];
app.GroundcgtrailerEditField.Position = [179 661 100 22];
Is there somewhere else?
Jyotsna Talluri
Jyotsna Talluri 2019년 11월 7일
If you are declaring the inputs through the Numeric edit fields ,the it should work fine.Can you share the entire code in a .m file and the app layout screenshot so that I can check once?

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

카테고리

Help CenterFile Exchange에서 Package and Share Apps에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by