How to run batch of peak finding on data?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-2-15
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 个评论
Star Strider
2022-2-17
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!