Data set must contain at least 3 samples error in find peaks embedded in for loop
9 次查看(过去 30 天)
显示 更早的评论
Hi All,
I am trying to iterate through the columns of a matrix I have called 'data' to find the peaks of each column. To do this, I have a for loop that essentially looks like this:
for i = 1:size(data,2);
[pks{i,:},locs{i,:}] = findpeaks(bcgFixed(i,:),'MinPeakProminence',(bcgthresh*bcgStd),'MinPeakDistance', ((6/frate)* 10^-3)); %find all points where the baseline-subtracted background trace crosses 2*std
numEvents = length(locs)
% disp(locs)
% figure
% findpeaks(bcgFixed(i,:),'MinPeakProminence',(bcgthresh*bcgStd),'MinPeakDistance', ((1/frate)* 10^-3));
end
when I try to run the code it gives me the error message in the title. I'm not sure why because this matrix contains a lot more than 3 samples. Would really appreciate some help with this one.
0 个评论
采纳的回答
Star Strider
2019-11-10
‘... columns of a matrix ...’
Note that:
[pks{i,:},locs{i,:}] = findpeaks(bcgFixed(i,:),'MinPeakProminence',(bcgthresh*bcgStd),'MinPeakDistance', ((6/frate)* 10^-3)); %find all points where the baseline-subtracted background trace crosses 2*std
will iterate across rows.
To iterate across columns, use:
bcgFixed(:,i)
instead:
[pks{i,:},locs{i,:}] = findpeaks(bcgFixed(:,i),'MinPeakProminence',(bcgthresh*bcgStd),'MinPeakDistance', ((6/frate)*1E-3)); %find all points where the baseline-subtracted background trace crosses 2*std
The cell arrays storing the output do not care, however the input array does.
12 个评论
Star Strider
2019-11-10
I apologise for the delay — sleeping.
I cannot understand what you are doing, especially with:
bcgMean1 = repelem(bcgMean(1:1750:end,:),1750,1);
Note that you can calculate the row means of ‘valarray’ as:
bcgMean = mean(valarray);
so including it in the loop is unnecessary.
Here you are using the last column (whatever the last value of ‘i2’ was in the previous loop) of ‘bcgMean1’:
bcgFixed(i) = (valarray(:,i) - bcgMean1(:,i2)); %subtract mean to center at zero
from all of ‘valarray’, column-wise. If they do not have the same row sizes, that would throw the error you are seeing.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!