Dear all,
The 'Pilant_Vy_envR' (xlsx) file is of these dimensions: 1200x600. Every column is a signal, and i would like to find the three main peaks (non sorted) in every column. I'm stuck with the following code:
ncolVy=size(Pilant_Vy_envR,2);
max = zeros(ncolVy,3) ;
for l = 1:ncolVy
[PKSVy,locs] = findpeaks(Pilant_Vy_envR(:,l));
maxvy(l,:) = maxk(PKSVy,3);
MaxVy = maxvy.';
end
The output contain 3x600 columns. Three are the maxima obtained by every signal, but the code above sort them. I would like infact to obtain the peaks as they are in the graph.
So for example for the first signal (first column) i would like the peaks with their order:
But with maxk i have the peaks with the order:1-3-2.
Can someone help me?
Best regards.

 채택된 답변

Voss
Voss 2022년 7월 8일
편집: Voss 2022년 7월 8일

0 개 추천

% a smaller example:
Pilant_Vy_envR = zeros(13,2);
Pilant_Vy_envR(2:3:end,1) = [30; 15; 10; 20];
Pilant_Vy_envR(3:3:end,2) = [25; 17; 32; 16];
% 2 signals with 4 peaks each
disp(Pilant_Vy_envR)
0 0 30 0 0 25 0 0 15 0 0 17 0 0 10 0 0 32 0 0 20 0 0 16 0 0
% number of columns/signals
ncolVy = size(Pilant_Vy_envR,2);
% (initialize MaxVy with its right size)
MaxVy = zeros(3,ncolVy);
for col = 1:ncolVy
% first, find all the peaks (don't need the locations "locs" for this)
PKSVy = findpeaks(Pilant_Vy_envR(:,col));
% use the 2nd output of maxk, which is the indices of the 3 highest peaks
[three_peaks,idx] = maxk(PKSVy,3);
% sort those indices, and use the second output from sort, which is
% their order when sorted
[~,jj] = sort(idx);
% put the 3 highest peaks in the same order
MaxVy(:,col) = three_peaks(jj);
end
disp(MaxVy);
30 25 15 17 20 32

댓글 수: 2

Mattia Fattori
Mattia Fattori 2022년 7월 9일
Dear Voss,
now understand my mistakes, and the problem seems to be solved.
Thanks a lot for your help!
Voss
Voss 2022년 7월 9일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2022년 7월 8일

댓글:

2022년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by