Number of peaks in the interval
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-8-15
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 个评论
Star Strider
2022-8-15
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.
.
更多回答(2 个)
Benjamin Thompson
2022-8-15
Use MinPeakHeight as the parameter name for findpeaks. You do not show the definition of locsI or psk in your sample code.
0 个评论
Image Analyst
2022-8-15
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!