Clear Filters
Clear Filters

fitting a certain function up to a certain x-value

1 view (last 30 days)
Hello,
I have data in a two coulmns-excel file and I load them then I perform a fitting using a defined equation. I need to perform the fitting until a user defined value of x-axis. To have an equal length of x and y, I tried to look for the y value corresponding to the given x value. The code is:
dataset = xlsread('input.xlsx');
E=dataset(:,1);
F3g=dataset(:,2);
%Equation
f = @(x,Edata)(x(1)+(x(2)-x(1))*exp(-0.5*(Edata/x(3)).^x(4)))./(1+(Edata/x(5)).^1.6)+x(6)*((x(7)-x(8))./(Edata/x(9))+x(8));
x0 = [0 0 0 1 1 1 0 1 0];
Ev=getappdata(0,'edit3'); % this is an editable value by user
Z=F3g(E==Ev); % I try to get the value of F3g corresponding to Ev to have equal lengths
options = optimoptions('lsqnonlin','Display','iter');
[x,resnorm,~,exitflag,output] = lsqcurvefit(f,x0,E(1:Ev),F3g(1:Z),[],[], options) % fitting
1-It does not work and it shows the error;
Error using ==
Matrix dimensions must agree.
2-Also, If I set manually the number of column of F3g corresponding to the given value of Ev, e.g.,
[x,resnorm,~,exitflag,output] = lsqcurvefit(f,x0,E(1:Ev),F3g(1:19),[],[], options) % fitting
it shows the following error!
Error using :
For colon operator with char operands, first and last operands must be char.
it works only with
[x,resnorm,~,exitflag,output] = lsqcurvefit(f,x0,E(1:19),F3g(1:19),[],[], options) % fitting
But without using Ev while I need to use it. Any help or hints?
Thanks in advance

Answers (0)

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!