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!