I want to substract fit values from original data. Here is my code. What is wrong? Why Z and fitresult values are not equal? (see plot)
[xData, yData] = prepareCurveData(xdata,zz);ft = fittype( 'sin4' );opts = fitoptions( 'Method', 'NonlinearLeastSquares' );opts.Normalize = 'on';[fitresult, ~] = fit(xData, yData, ft, opts );warning('off','curvefit:fit:equationBadlyConditioned')x = xData;y = yData;varnames = coeffnames(fitresult)varvalues = coeffvalues(fitresult)for i = 1:length(varnames) eval([varnames{i},'=',num2str(varvalues(i)),';']);endZ = a1*sin(b1*x+c1) +a2*sin(b2*x+c2) +a3*sin(b3*x+c3) + a4*sin(b4*x+c4);figureplot(x,y)hold onplot(fitresult)plot(x,Z)legend('data','fit function','fit exact values')%%
z_INT = Z_int-Z;
Best Answer