How can I use a for loop to find multiple minimum values in a matrix array?

1 次查看(过去 30 天)
Hello, Everyone
I'm working on spike sorting algorthim and I want to store multiple manium values in an array. (Descsending then ascending). but my code only stores on value
thresh = mean(abs(data))*tf;
data_len=size(data);
idx= []
for i= 1:1:data_len
if(data < thresh)
idx=find(data(:) == min(data(:)));
idx=[idx ]
end
end
  1 个评论
Matt J
Matt J 2022-1-11
Anas Wheba's comment moved here:
The main aim is to detect the spikes by comparing the points on a spike that been detected by the threshold, when the location of the spike is detected we should compare two points on the signal and if the second point let's call it point B is smaller than the first point ( called A) the code must continue comparing when the code reaches two points for example point C and D and when we compare those two points points D which is located before after point C in bigger than it the code will stop and store the value as an array of numbers. As shown in figure below it will detect a portion of the signal.

请先登录,再进行评论。

回答(2 个)

Matt J
Matt J 2022-1-11
You are not using the loop variable i anywhere.
  12 个评论
Torsten
Torsten 2022-1-11
编辑:Torsten 2022-1-11
The first line of the code finds the minimum value of that part of your data that are smaller than the threshold.
The second line finds all indices in your complete data vector where this minimum is attained.
If locations = 40 is what MATLAB returns, there is only one index in the data vector with this minimum as array element, namely data(40).
If you want something different from what the two lines of code do, please describe it in your own words.
Anas Wheba
Anas Wheba 2022-1-11
The main aim is to detect the spikes by comparing the points on a spike that been detected by the threshold, when the location of the spike is detected we should compare two points on the signal and if the second point let's call it point B is smaller than the first point ( called A) the code must continue comparing when the code reaches two points for example point C and D and when we compare those two points points D which is located before after point C in bigger than it the code will stop and store the value as an array of numbers. As shown in figure below it will detect a portion of the signal.

请先登录,再进行评论。


Matt J
Matt J 2022-1-11
编辑:Matt J 2022-1-11
A=data(1:end-3);
B=data(2:end-2);
C=data(3:end-1);
D=data(4:end);
locations=find(A>B & B>C & C<D)+2,

类别

Help CenterFile Exchange 中查找有关 Electrophysiology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by