Number of peaks in the interval
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lev Mihailov
le 15 Août 2022
Réponse apportée : Image Analyst
le 15 Août 2022
There is a long vector (20002 values long) that I need to split into intervals (100 each) and find out the number of peaks in this interval
% P3 may data
step = 100;
for i = 1:size(T,2)-step
i1 = P3(i:i+step);
[psk(i),length(locsI(i))] = findpeaks(i1,'MinPeakHeigh',-0.55,'MinPeakDistance',5);
end
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in DataLen (line 2146)
[psk(i),length(locsI(i))] = findpeaks(i1,'MinPeakHeigh',-0.55,'MinPeakDistance',5);
I tried this code, but it shows this error
Thank you in advance!
0 commentaires
Réponse acceptée
Star Strider
le 15 Août 2022
A simpler way (if you have the Signal Processing Toolbox) would be to use the buffer function to segment the vector. Then, simply index into its columns with findpeaks, saving them as cell arrays —
I1bfr = buffer(i1, 100);
for k = 1:size(i1bfr,2)
[psk{i},locs{i}] = findpeaks(i1bfr(:,k),'MinPeakHeigh',-0.55,'MinPeakDistance',5);
end
I created a function that will do the most basic result of buffer and will post it if you need it.
.
3 commentaires
Star Strider
le 15 Août 2022
I generally use ‘k’ asd a loop counter and I overlooked that. Changing it to ‘i’ —
i1 = randn(1, 20002); % Create Vector
i1bfr = buffer(i1, 100);
for i = 1:size(i1bfr,2)
[psk{i},locs{i}] = findpeaks(i1bfr(:,i),'MinPeakHeight',-0.55,'MinPeakDistance',5);
end
Check_col = randi(size(i1bfr,2)) % Random Column
Check_psk = psk{Check_col}
Check_locs = locs{Check_col}
That should work.
.
Plus de réponses (2)
Benjamin Thompson
le 15 Août 2022
Use MinPeakHeight as the parameter name for findpeaks. You do not show the definition of locsI or psk in your sample code.
0 commentaires
Image Analyst
le 15 Août 2022
Twenty thousand is not a long vector. You can use findpeaks on the whole thing and split it up later. This will avoid any "edge effects" from where you split your vector.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
save('answers.mat', 'T', 'p3');
And, as Star showed, you can't use length in the output argument list. And you need to use cell arrays (use braces instead of parentheses). See the FAQ:
Corrected code
[psk{i}, locsI{i} = findpeaks(i1,'MinPeakHeight',-0.55,'MinPeakDistance',5);
If you need the length of it (but it does not look like you do), then compute it afterwards
0 commentaires
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!