# Custom m-file function in fitting tool

4 visualizzazioni (ultimi 30 giorni)
Thomas il 23 Gen 2011
Dear Sir/Madam, I have a question regarding the fitting tool. I was wondering if it is possible to use a custom function from a m-file in an equation used for fitting.
Thanks in advance, Thomas van der Vliet
##### 1 CommentoMostra NessunoNascondi Nessuno
bym il 23 Gen 2011
the basic tool does not provide for custom functions. If you could provide more information about you data and custom function, perhaps there is a work around

Accedi per commentare.

### Risposte (1)

Jon Cherrie il 30 Mar 2011
Yes, it is possible to use a Custom Equation in CFTOOL defined from a MATLAB file. Here is an example. Start by creating a file like this:
function y = my_curve( x, a, b, c )
y = zeros( size( x ) );
isLeft = x < 0.5;
y(isLeft) = a + b*x(isLeft);
y(~isLeft) = a + c*x(~isLeft);
end
1. it has an input for the x-data, x
2. it has one input for each coefficient, a, b and c.
3. the y-data, y, that is returned is the same size as x
4. it will work when the x-data, x, is a vector.
In CFTOOL you can then follow the usual steps to create a Custom Equation. Choose a General rather than Linear equation. For the equation, enter my_curve( x, a, b, c ).
If you need a surface, then you can do all the same stuff in SFTOOL, just add an input argument for y-data and make sure that your function works when the x- and y-data are vectors.
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Get Started with Curve Fitting Toolbox 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!