Issue using lsqcurvefit function - App Designer
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hélène
il 26 Mag 2023
Commentato: Cris LaPierre
il 26 Mag 2023
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
Risposta accettata
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
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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!