Bonjour à tous,

Je suis totalement débutant en MATLAB mais je programme déja un peu en C++.
J'ai une version étudiant 2009 avec le module "curve fitting" (une version achetée je vous rassure).

Je dispose d'une série de 48 points (X,Y) que je souhaite fitter selon un algorithme de Levenberg Macquard par une équation du type :

a1*exp(-b1 * x) + a2*exp(-b2 * x) + a3*exp(-b3 * x) + c

Cela marche parfaitement avec la "curve fitting toolbox" et j'ai exactement les résultats que j'attendais. J'ai donc fait un export de ma toolBox en m file pour intégrer le code dans mon programme. En effet, ce n'est pas pratique de rentrer dans la toolbox et de tout paramétrer à la main à chaque fois. surtout que j'ai plusieurs milliers de séries à fitter...
MAIS le code ne veut pas s'éxécuter ! Je n'ai pas d'erreur à la "compilation" mais à l'éxécution.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
function createFit(X,Y)
%CREATEFIT    Create plot of datasets and fits
%   CREATEFIT(X,Y)
%   Creates a plot, similar to the plot in the main curve fitting
%   window, using the data that you provide as input.  You can
%   apply this function to the same data you used with cftool
%   or with different data.  You may want to edit the function to
%   customize the code and this help message.
%
%   Number of datasets:  1
%   Number of fits:  1
 
 
% Data from dataset "Y vs. X":
%    X = X:
%    Y = Y:
%    Unweighted
%
% This function was automatically generated on 29-Jan-2010 09:53:18
 
% Set up figure to receive datasets and fits
f_ = clf;
figure(f_);
set(f_,'Units','Pixels','Position',[609 262 672 475]);
legh_ = []; legt_ = {};   % handles and text for legend
xlim_ = [Inf -Inf];       % limits of x axis
ax_ = axes;
set(ax_,'Units','normalized','OuterPosition',[0 0 1 1]);
set(ax_,'Box','on');
axes(ax_); hold on;
 
 
% --- Plot data originally in dataset "Y vs. X"
X = 0 : 100: 4700  ;
Y =[161.877090454 130.790496826 110.902236938 99.430168152 89.581008911 80.266761780 72.627098083 66.621505737 61.547485352 57.162010193 53.522346497 50.156425476 47.008380890 44.885475159 42.467876434 40.467876434 38.569831848 36.857540131 35.279331207 34.244415283 33.072624207 30.903631210 30.374301910 29.889665604 28.684356689 27.621507645 27.357542038 26.181564331 25.824022293 25.326816559 24.822626114 24.201116562 23.846368790 23.666200638 23.675977707 21.441341400 22.395252228 22.525138855 22.308658600 21.645252228 21.569831848 21.406425476 20.974861145 20.075418472 20.983240128 20.571229935 20.451116562 19.597764969] ;
 
h_ = line(X,Y,'Parent',ax_,'Color',[0.333333 0 0.666667],...
    'LineStyle','none', 'LineWidth',1,...
    'Marker','.', 'MarkerSize',12);
xlim_(1) = min(xlim_(1),min(X));
xlim_(2) = max(xlim_(2),max(X));
legh_(end+1) = h_;
legt_{end+1} = 'Y vs. X';
 
% Nudge axis limits beyond data limits
if all(isfinite(xlim_))
    xlim_ = xlim_ + [-1 1] * 0.01 * diff(xlim_);
    set(ax_,'XLim',xlim_)
else
    set(ax_, 'XLim',[-47, 4747]);
end
 
 
% --- Create fit "fit 1"
fo_ = fitoptions('method','NonlinearLeastSquares','Algorithm','Levenberg-Marquardt');
ok_ = isfinite(X) & isfinite(Y);
if ~all( ok_ )
    warning( 'GenerateMFile:IgnoringNansAndInfs', ...
        'Ignoring NaNs and Infs in data' );
end
st_ = [100 60 15 0.0030000000000000000625 0.0020000000000000000416 0.0010000000000000000208 10 ];
set(fo_,'Startpoint',st_);
ft_ = fittype('a1*exp(-b1*x)+a2*exp(-b2*x)+a3*exp(-b3*x)+c',...
    'dependent',{'y'},'independent',{'x'},...
    'coefficients',{'a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c'});
 
% Fit this model using new data
cf_ = fit(X(ok_),Y(ok_),ft_,fo_);
 
% Or use coefficients from the original fit:
if 0
    cv_ = { 18.493034076364804008, 61.525025207391735194, 63.593359226641375415, 0.013545930806642533448, 0.002419059790810983851, 0.0007611076460613920092, 18.319483904677376529};
    cf_ = cfit(ft_,cv_{:});
end
 
% Plot this fit
h_ = plot(cf_,'fit',0.95);
legend off;  % turn off legend from plot method call
set(h_(1),'Color',[1 0 0],...
    'LineStyle','-', 'LineWidth',2,...
    'Marker','none', 'MarkerSize',6);
legh_(end+1) = h_(1);
legt_{end+1} = 'fit 1';
 
% Done plotting data and fits.  Now finish up loose ends.
hold off;
leginfo_ = {'Orientation', 'vertical', 'Location', 'NorthEast'};
h_ = legend(ax_,legh_,legt_,leginfo_{:});  % create legend
set(h_,'Interpreter','none');
xlabel(ax_,'');               % remove x label
ylabel(ax_,'');               % remove y label
J'obtiens le message suivant :
??? XDATA must be a matrix with one to two columns.

Error in ==> fit at 116
errstr = handleerr('curvefit:fit:xDataMustBeColumnVector', ...

Error in ==> createFit at 68
cf_ = fit(X(ok_),Y(ok_),ft_,fo_);