How do I find peaks in a matrix and extract those values?
8 views (last 30 days)
Show older comments
I have a matrix that is 3 columns wide. How do I find all the peaks in column 2 and pull them out with their associated values in columns 1 and 3? I would like to save these values in a new matrix.
Edit: which column I want, I didn't desribe the correct situation the first time.
Also Included image of what happens when I try to used findpeaks()

0 Comments
Accepted Answer
Star Strider
on 3 Jul 2019
I would do something like this:
YourMatrix = rand(20, 3); % Create Matrix
[pks,locs] = findpeaks(YourMatrix(:,1)); % Column #1 Peaks & Indices
for k = 1:2
PkVals(:,k) = YourMatrix(locs, k+1); % Corresponding Values For Columns #2 & #3
end
Experiment to get the results you want.
5 Comments
Star Strider
on 8 Nov 2021
This should actually be a new Question.
That aside:
time = (0:0.5:10).';
B = 1E4*exp(-(time-5.5).^2);
T = table(time,B)
[pks,locs] = findpeaks(T.B, 'MinPeakHeight',6800);
times = T.time(locs,:)
A Vote would be appreciated!
.
Gabriel G
on 8 Nov 2021
Thanks, it works well for any other column in the table now.
I'll keep in mind for the next time to create a new question.
More Answers (1)
Image Analyst
on 3 Jul 2019
Have you tried findpeaks() in the Signal Processing Toolbox?
How exactly do you define a peak? It's not so clear cut as you might think.
You forgot to attach your data or any screenshots. Make it easy for people to help you and you'll get more useful answers.
2 Comments
Image Analyst
on 3 Jul 2019
Yes but no data is attached yet, and there's not even a screenshot of your signal plotted.
Please read this link
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!