# I have 400 columns of matrix, I want to calculate FWHM. I'm trying find codes related to find peaks, but nothing works. I cannot see the FWHM as 400 different columns.

1 vue (au cours des 30 derniers jours)
bhargavi veeraghattam le 14 Avr 2023
Commenté : dpb le 19 Avr 2023
y=data(:,2:end);
x=data(:,1);
plot(x,y);
m2= max(data(:,2:end));
[M,I]= max(data);
m3= min(data(:,2:end));
[M1,I1]= min(data);
halfMax = (min(y(:,1:end)) + max(y(:,1:end))) / 2;
for n=1:length(y)
% Find where the data first drops below half the max.
index1 = find(y(:,n) >= halfMax(:,n), 1, 'first');
% Find where the data last rises above half the max.
index2 = find(y(:,n) >= halfMax(:,n), 1, 'last');
fwhm = index2-index1 + 1; % FWHM in indexes.
fwhmx = x(index2) - x(index1);
end
##### 2 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
bhargavi veeraghattam le 15 Avr 2023
y=data(:,2:end);
x=data(:,1);
plot(x,y);
plot(x,-y);
m2= max(data(:,2:end));
[M,I]= max(data);
m3= min(data(:,2:end));
[M1,I1]= min(data);
halfMax = (min(y(:,1:end)) + max(y(:,1:end))) / 2;
for n=1:length(y)
% Find where the data first drops below half the max.
index1 = find(y(:,n) >= halfMax(:,n), 1, 'first');
% Find where the data last rises above half the max.
index2 = find(y(:,n) >= halfMax(:,n), 1, 'last');
fwhm = index2-index1 + 1; % FWHM in indexes.
fwhmx = x(index2) - x(index1);
end

Connectez-vous pour commenter.

### Réponse acceptée

dpb le 15 Avr 2023
Modifié(e) : dpb le 19 Avr 2023
whos data
Name Size Bytes Class Attributes data 609x558 2718576 double
plot(data(:,1),data(:,[2:6 end-5 end]))
xlim([625 675]);ylim([25 35]) Seems to be very similar traces with only a very tiny change between; by time get from start to finish is some variation...
[MN,IMN]=min(data(:,2:end)); [MX,IMX]=max(data(:,2:end));
figure
subplot(3,1,1);plot([MN;MX].')
subplot(3,1,2);plot([MN;MX].');xlim([30 80])
Something really peculiar seems to be going on in an early section; the traces between columns 50-70 must be almost flat and there may not be any real peaks...
subplot(3,1,3)
plot(data(:,1),data(:,48:53))
legend(string([48:53].')) May need to do something special there, but the brute force way should work for most of the rest, anyway...
FWHM=nan(size(MX));
H=mean([MX;MN]);
for i=1:numel(MX)
f1=find(data(1:IMX(i),i+1)>=H(i),1);
f2=find(data(IMX(i):end,i+1)<=H(i),1)+IMX(i);
try % in case those odd spectra fail
FWHM(i)=f2-f1;
catch
end
end
nnz(isnan(FWHM)) % so how many did?
ans = 2
find(isnan(FWHM)) % which ones, specifically?
ans = 1×2
69 70
figure
plot(data(:,1),data(:,ans)) % what do they look like? I didn't try your identical code, but one guesses the problem is simply that you didn't plot your data first (or last) to ensure it all made sense to try to compute what were trying to compute...
Let's look at the possible issue of width of peaks raised below -- we've got the data here; we'll not redo the calc's...
figure
plot(FWHM)
xlim([0 100]) % adjusted after observed result Seems pretty consistent except for that area already identified as problematical; you'll have an idea what to do about those, one presumes. Overall, may be better than I had feared...
##### 3 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
dpb le 19 Avr 2023
ERRATUM: I just realized I had forgotten to add the IMX(i) location onto the second found position to account for starting the search from the maximum location on...I fixed the code in the Answer but be sure to make that in your own code; otherwise the location found is the right one, just relative to the peak, not the first so the FWHM number is incorrect.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!