Number of peaks in the interval
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Lev Mihailov
el 15 de Ag. de 2022
Respondida: Image Analyst
el 15 de Ag. de 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 comentarios
Respuesta aceptada
Star Strider
el 15 de Ag. de 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 comentarios
Star Strider
el 15 de Ag. de 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.
.
Más respuestas (2)
Benjamin Thompson
el 15 de Ag. de 2022
Use MinPeakHeight as the parameter name for findpeaks. You do not show the definition of locsI or psk in your sample code.
0 comentarios
Image Analyst
el 15 de Ag. de 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 comentarios
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!