How to run batch of peak finding on data?

3 visualizaciones (últimos 30 días)
Sam
Sam el 15 de Feb. de 2022
Comentada: Star Strider el 17 de Feb. de 2022
I am writing a script in order to locate the exact position of one peak, run this on hundred + sample .dat files and then spit out a .txt file with the peak position for each sample/.dat file. Unfortunately, I am struggling to use fitpeaks.
The data looks like this and I am looking to find the peak position at approx. 0.01.
data = readmatrix('exampledata.dat') ; % load the data from text file
graph = plot(data(:,1),data(:,2))
findpeaks(graph)
It plots the data nicely, but won't find any peaks, so I get this error:
Error using findpeaks
Expected Y to be one of these types:
double, single
Instead its type was matlab.graphics.chart.primitive.Line.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in PeakFinderS (line 4)
findpeaks(graph)
I have attached example data.

Respuesta aceptada

Star Strider
Star Strider el 15 de Feb. de 2022
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/895415/exampledata.txt')
data = 1268×3
0.0017 0.0103 0.0001 0.0018 0.0730 0.0004 0.0019 0.2810 0.0006 0.0021 0.2447 0.0004 0.0022 0.2747 0.0003 0.0023 0.3600 0.0003 0.0024 0.3246 0.0002 0.0025 0.2888 0.0002 0.0026 0.2204 0.0002 0.0028 0.2311 0.0002
[pks,locs,wdt,prm] = findpeaks(data(:,2), 'MinPeakDistance', 50);
figure
graph = plot(data(:,1),data(:,2));
hold on
plot(data(locs,1), data(locs,2), '^r')
hold off
xlim([0 0.05])
text(data(locs(2),1), data(locs(2),2), sprintf(' \\leftarrow (%.4f, %.4f)',data(locs(2),1), data(locs(2),2)), 'Horiz','left', 'Vert','bottom', 'Rotation',45)
I am not certain what the desired result is. This is one way of getting something close to it.
.
  14 comentarios
Sam
Sam el 17 de Feb. de 2022
This has worked! Thank you so much @Star Strider, you have been such a huge help, I really appreciate your persistance to help me!
Star Strider
Star Strider el 17 de Feb. de 2022
As always, my pleasure!
This is an interesting problem. I never considered using the technique here to isolate peaks in a specific region of the independent variable before,so I learned something.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by