How to run batch of peak finding on data?
4 ビュー (過去 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!