Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Anas Wheba
Anas Wheba am 11 Jan. 2022
Bearbeitet: Matt J am 11 Jan. 2022
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 Kommentar
Matt J
Matt J am 11 Jan. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Matt J
Matt J am 11 Jan. 2022
You are not using the loop variable i anywhere.
  12 Kommentare
Torsten
Torsten am 11 Jan. 2022
Bearbeitet: Torsten am 11 Jan. 2022
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 am 11 Jan. 2022
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.

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 11 Jan. 2022
Bearbeitet: Matt J am 11 Jan. 2022
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,

Kategorien

Mehr zu Electrophysiology finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by