0

我有一个适合指数的数据。数据是具有 3-4 个峰的光谱。我想在这些峰的尾部拟合指数。但是当我使用 f=fit(X,Y,'exp1'); 时,matlab 正在拟合整个光谱的曲线,而不是光谱的选定区域。这是因为,我认为,所选区域不在 X 轴的零处(我使用 ginput 命令选择一个区域,然后将其分开以进行曲线拟合)。因此,据我了解,Matlab 是从 x 轴的零点开始绘制的,这样就出错了。如何摆脱这一点并获得符合指数的数据的选定区域?%%读取文件并绘制光谱

function DA13_07_09;

cdir='\\ST-Computer\data\clusters\';

LsTimes=[0, 29906, 129892, 229878];
ScList.t0_us=LsTimes-3000;
ScList.t0_us(1)=0;
ScList.BinW_us=  [100  , 200    , 200     , 200     ];
ScList.tf_us=LsTimes+10E+3; ScList.tf_us(1)=1E+6;

fname='Xe6_550nm_0030';
rf=0;
if rf
F=ReadMSFile2([cdir, fname, '.dat'], ScList);
eval (['save ', fname, ' F;']);
else
eval (['load ', fname]);
end;
pf=1;
if pf
figure(1); clf;
semilogy(F.data{1}.tt_us/1e+3, F.data{1}.yy_counts, '.-');
PrepFig(1, 'time after injection (ms)', 'counts', fname);

AL=round(min([length(F.data{2}.tt_us), length(F.data{3}.tt_us), length(F.data{4}.tt_us)])*2/3);
tsum=F.data{2}.tt_us(1:AL)-LsTimes(2);
ysum=F.data{2}.yy_counts(1:AL)+F.data{3}.yy_counts(1:AL)+F.data{4}.yy_counts(1:AL);

figure(2); clf;
semilogy(F.data{2}.tt_us-LsTimes(2), F.data{2}.yy_counts, '-', ...
    F.data{3}.tt_us-LsTimes(3), F.data{3}.yy_counts, '-', ...
    F.data{4}.tt_us-LsTimes(4), F.data{4}.yy_counts, '-', ...
    tsum, ysum, '-');
legend({'29 ms', '129 ms', '229 ms', 'sum'});
PrepFig(2, 'time after laser (\mus)', 'counts', fname);
end;

%% To plot and fit the curve
A=F.data{1}.tt_us/1e+3;
B=F.data{1}.yy_counts;
[xclick, yclick]=ginput(2);
tIndex=find(A>=xclick(1,1)&A<=xclick(2,1));
t1=(A(tIndex))';
C1=(log(B(tIndex)))';

f=fit(t1,C1,'exp1');
figure(3);
plot(f,t1,C1)
4

1 回答 1

1

您确定要存储 ginput 中的值吗?X 和 Y 是什么?它们是光谱数据吗?

要仅拟合部分数据,您必须使用以下方法创建数据子集(假设 X 和 Y 是完整的光谱数据):

fig=figure;
plot(X,Y);
[selectX selectY]=ginput(2); % select a start and end point
% take only the data portion between the start and end points 
% (using min and max in case the user clicks the end point first)
sub_indices=(X>=min(selectX) & X<=max(selectX)); 
subX=X(sub_indices);
subY=Y(sub_indices);
f=fit(subX,subY,'exp1');
于 2013-07-16T11:41:18.720 回答