How to parse different dimension ydata in lsqcurvefit using cell arrays?
2 次查看(过去 30 天)
显示 更早的评论
Hi. I have compiled all my observed data (of different dimensions) in separate cells e.g.
y{1}=[];
for input_trace=1:h; % h= no of files from which ydata is imported where filenames are time(1) etc..
import=['time(' int2str(input_trace) ')'];
ydata=xlsread(import); %import of files
y(input_trace)={ydata(:,2)}; %
end
and so I have collection of ydata and also my functions output is arranged accordingly.
ini_param=[A,B,Z]; %initial parameters
options = optimset('DiffMinChange',[0.000001],'disp','iter','Algorithm','levenberg-marquardt','MaxIter',100000,'MaxFunEvals',[10000]);%simple max eval fun 100000
options = optimset(options, 'TolX', 1e-14);
[fitted_param,resnorm,fval,output]= lsqcurvefit( @(ini_param,x) functionname(ini_param,x),ini_param,x,y,lb,ub,options);
In this way my ydata is like
y =
Columns 1 through 6
[0.0156] [320x1 double] [-0.0212] [203x1 double] [199x1 double] [1.0034e-04]
Columns 7 through 11
[246x1 double] [0.0348] [242x1 double] [225x1 double] [340x1 double]
When I run the program it gives error
Error using lsqcurvefit (line 182)
LSQCURVEFIT requires the following inputs to be of data type double: 'YDATA'.
Error in functionname(line 204)
[fitted_param,resnorm,fval,output]= lsqcurvefit( @(ini_param,x)
functionname(ini_param,x),ini_param,x,y,lb,ub,options);
What am I doing wrong?
0 个评论
回答(1 个)
Walter Roberson
2017-2-9
lsqcurvefit does not accept cell arrays for x or y.
You may need to loop doing one y item at a time.
2 个评论
Walter Roberson
2017-2-9
Fitting requires that the size of the input (independent variable, each xi) matches the size of the output (each yi). You cannot, for example, use a 57 x 1 vector of x to calculate a 34 x 1 y.
It could make sense to use the same x with different y that are the same size as each other, and it could make sense to use different x with y of corresponding size. For example,
for K = 1 : length(y)
[fitted_param{K}, resnorm{K}, fval{K}, output{K}]= lsqcurvefit( @(ini_param,xi) functionname(ini_param, x{K}), ini_param, x{K} , y{K}, [], [], options);
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!