필터 지우기
필터 지우기

Issue using lsqcurvefit function - App Designer

조회 수: 1 (최근 30일)
Hélène
Hélène 2023년 5월 26일
댓글: Cris LaPierre 2023년 5월 26일
Good morning,
I'm new to App Designer, and I need to solve an optimization problem using the lsqcurvefit function.
I reuse pre-existing calculation codes, I defined a function
F1=myfun_root(app,x,Speed_sample_RPM)
as a private function in the application code. In this same code, I call the lsqcurvefit function in a CallBack Button:
[x,resnorm,residual,exitflag,output] = ...
lsqcurvefit(@myfun_root,app.x0,Speed_sample_RPM_zoom_T,yt_sample_zoom_Total_Nondim,app.lb,app.ub);
All the variables used are defined previously in the code, which I cannot copy/paste here.
When I run the application and click on the button to calculate the interpolation which launches the CallBack including the lsqcurvefit function, I get the error message:
Error using nargin
Function myfun_root does not exist.
While the latter is well defined as a function at the beginning of the program.
I searched on the Q/A of Matlab but I did not find an already existing answer to this concern, of which I do not understand the cause.
Could someone please enlighten me?
I thank you in advance !
  댓글 수: 1
Torsten
Torsten 2023년 5월 26일
편집: Torsten 2023년 5월 26일
While the latter is well defined as a function at the beginning of the program.
As a function handle ? If it is defined as a function, it must be included at the end of the program (script).

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

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 5월 26일
Since you didn't share your code, I created a simple example in app designer using this example from the lsqcurvefit documentation page. I made the following observations after comparing to what you've shared.
You haven't defined your function correctly. I would expect it to look something like this
function F1=myfun_root(app,x,Speed_sample_RPM,Speed_sample_zoom)
In addition, your calling syntax needs to be modified to work inside app designer.
[x,resnorm,residual,exitflag,output] = ...
lsqcurvefit(@app.myfun_root,app.x0,Speed_sample_RPM_zoom_T,yt_sample_zoom_Total_Nondim,app.lb,app.ub);
This of course assumes all other variables have been propertly defined.
  댓글 수: 2
Hélène
Hélène 2023년 5월 26일
Thank you for your two answers which made it possible to solve this first problem. @Cris la Pierre I'm not sure I understand adding a third argument to the F1 function.
When I run the code now I get another error message:
Error using assert
FUN must have two input arguments.
However, the myfun_root function has two input arguments, x0 and Speed_sample_RPM_zoom, so I don't really understand the correction to be made.
I'm sorry, this may seem basic to you, but I'm new to Matlab on the one hand and App Designer on the other.
I thank you in advance !
Cris LaPierre
Cris LaPierre 2023년 5월 26일
That was me trying to take a guess at what your code was doing. I had to try a couple things to get the example to run in App Designer, and just didn't go back and minimize the code.
You can remove the 3rd input argument from myfun_root
function F1=myfun_root(app,x,Speed_sample_RPM)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by