Issue using lsqcurvefit function - App Designer

5 visualizzazioni (ultimi 30 giorni)
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 Commento
Torsten
Torsten il 26 Mag 2023
Modificato: Torsten il 26 Mag 2023
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).

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 26 Mag 2023
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 Commenti
Hélène
Hélène il 26 Mag 2023
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 il 26 Mag 2023
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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by