Apply 'findpeaks' in every column

4 visualizaciones (últimos 30 días)
Mattia Fattori
Mattia Fattori el 30 de Jun. de 2022
Comentada: Mattia Fattori el 30 de Jun. de 2022
Hi guys, i have a problem.
I have a (1200x600) matrix, where each column consists on a trace with at least 3 peaks, and i want to find the 3 maxpeaks in every column.
For the first trace (first column) the following code gives me the 3 max values:
Pilant_Vy_env = xlsread('Pilant_Vy_env.xlsx'); %The matrix is in .xlsx matlab spreadsheet format
first = Pilant_Vy_env(:,1);
[PKS,locs,~,prm] = findpeaks(first); %'first' is the first column of the matrix
[~,i] = sort(prm,'descend');
MAX = first(locs(i(1:3)));
plot(1:numel(first),first,'-',locs(i(1:3)),MAX,'o ')
What should i do if i want to use it for all the others 599 columns?
Thank you for your kind consideration,
Mattia
  2 comentarios
KSSV
KSSV el 30 de Jun. de 2022
Run a loop..
Mattia Fattori
Mattia Fattori el 30 de Jun. de 2022
Thanks KSSV. If i write the following code, what am i doing wrong?
ncol=size(Pilant_Vy_env);
for k = 1:ncol
[PKS,locs,~,prm] = findpeaks(Pilant_Vy_env(:,k));
[~,j] = sort(prm,'descend');
MAX = first(locs(j(1:3)));
end
%Error:Index in position 2 exceeds array bounds (must not exceed 600).
I would like to obtain a 3x600 matrix, with the max (first, second and third) in each column.
Thank you

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 30 de Jun. de 2022
Editada: KSSV el 30 de Jun. de 2022
ncol=size(Pilant_Vy_env,2);
MAX = zeros(ncol,3) ;
for k = 1:ncol
[PKS,locs,~,prm] = findpeaks(Pilant_Vy_env(:,k));
[~,j] = sort(prm,'descend');
MAX(k,:) = first(locs(j(1:3)));
end
  1 comentario
Mattia Fattori
Mattia Fattori el 30 de Jun. de 2022
Hi, i made a mistake previously. In MAX i should have written
MAX=Pilant_Vy_env(locs(j(1:3)))
So substituing that in
MAX(k,:) = Pilant_Vy_env(locs(j(1:3)));
%Here's the code
ncol=size(Pilant_Vy_env,2);
MAX = zeros(ncol,3) ;
for k = 1:ncol
[PKS,locs,~,prm] = findpeaks(Pilant_Vy_env(:,k));
[~,f] = sort(prm,'descend');
MAX(k,:) = Pilant_Vy_env(locs(f(1:3)));
end
plot(1:numel(Zerooff),Zerooff,'-',locs(f(1:3)),MAX(50,:),'o ')
as you suggested. But it finds only the peaks of the first column, where as (for example) in column 50 and also in others columns the max obtained have no sense:
Output without the cicle from column 50 (right)
Output from the code with cicle (column 50)..(No sense).
I have no idea...What could be the problem?
Best regards

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by