Is it possible to Peakfit a matrix?

I have been trying to make a loop for this matrix (575x100) it is 100 replicates of a spectrum. I want to peakfit each of the replicates and get the peak area from each one. I cannot figure out how to get matlab to output the data into a nice fashion. It analyzes the spectra but the table ends up only having one row of data. It should be 100x5. I am not matlab savvy by no means but I feel like there is a way (I just don't know how). Below is what I have. I used 1-5 only for times sake.
for x = [1:5]
s1table(1:end,1:5) = peakfit([shift,s1_led1(:,x)],1586,60,1,6,0,100,0,1);
end
this is another one I made yesterday, but I realized it didn't analyze all of the data, it just repeated the 5th replicate's peak fit 5 times. I really hope this is possible as it would save me so much time. I am open to other ideas, but I only have used numerical matrices... Please help.
for r = s1_led2(:,(x))
for x = 1:5
s1table((x),:) = peakfit([shift,(r)],1586,60,1,6,0,100,0,1);
end
end

3 Comments

peakfit() is not a MATLAB function. Please indicate where you got it so we can check.
Also please indicate size(shift) and size(sl_led1)
Mathieu is correct, that is what I used. I'm sorry for the confusion!
Also shift is 575 x 1 and s1_led1 is 575x100 matrix.

Sign in to comment.

 Accepted Answer

hello @Lindsey
you should normally be able use one or several of the outputs (but I don't know what you want)
FitResults,GOF,baseline,coeff,residual,xi,yi,BootResults
x=(linspace(0,10,575))';
y=exp(-(x-5).^2);
signal = [x y];
% [FitResults,GOF,baseline,coeff,residual,xi,yi,BootResults]=peakfit(signal,center,window,NumPeaks,peakshape,extra,NumTrials,start,autozero,fixedparameters,plots,bipolar,minwidth,DELTA,clipheight)
[FitResults,GOF,baseline,coeff,residual,xi,yi,BootResults] = peakfit(signal); % if you need all outputs
[FitResults] = peakfit(signal); % if FitResults suffices

4 Comments

a small demo on a dummy 575 x 10 matrix , if that helps :
% create a 575 x 10 matrix
x=(linspace(0,10,575))';
y=[];
for ck = 1:10
y=[y ck*exp(-(x-2-0.5*ck).^2)];
end
% [FitResults,GOF,baseline,coeff,residual,xi,yi,BootResults]=peakfit(signal,center,window,NumPeaks,peakshape,extra,NumTrials,start,autozero,fixedparameters,plots,bipolar,minwidth,DELTA,clipheight)
for ck = 1:10
FitResults(ck,:) = peakfit([x y(:,ck)]);
end
result :
FitResults =
1 2.5 1 1.6651 1.7721
1 3 2 1.6651 3.5449
1 3.5 3 1.6651 5.3174
1 4 4 1.6651 7.0898
1 4.5 5 1.6651 8.8623
1 5 6 1.6651 10.635
1 5.5 7 1.6651 12.407
1 6 8 1.6651 14.18
1 6.5 9 1.6651 15.952
1 7 10 1.6651 17.724
This is correct! It worked perfectly. Thank you so much!!!!
my pleasure !!
do you mind accepting my answer ? tx
yes of course! Thank you again!

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Asked:

on 13 Dec 2023

Commented:

on 13 Dec 2023

Community Treasure Hunt

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

Start Hunting!