How to run batch of peak finding on data?
4 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Star Strider
on 15 Feb 2022
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/895415/exampledata.txt')
[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 Comments
Star Strider
on 17 Feb 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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!