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

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 comentario

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.

Iniciar sesión para comentar.

Respuestas (2)

Matt J
Matt J el 11 de En. de 2022
You are not using the loop variable i anywhere.

12 comentarios

I tried to do it like that, but it did not work:
for i= 1:1:data_len
if(data < thresh)
idx=find(data(i) == min(data(i)));
end
end
"(data < thresh)" is only true if all elements of the array "data" are smaller than thresh.
Is this really what you mean in your if-statement ?
my data ranges from -100 to 100 when i plot them, I want to set my threshold to 50 so i can take the data from -50 to 50
i want to find multiple minium values then store them in an array
That would just be,
data=[2 3 5 2 7];
locations= find( data(:)==min( data(:) ) )
locations = 2×1
1 4
I tried it but it did not work, its the same with what i wrote
Torsten
Torsten el 11 de En. de 2022
Editada: Torsten el 11 de En. de 2022
It does not work because of your if-statement before. See my comment above.
And the loop is not necessary.
Sir, Im using the if statment because i want my data to range from -50 to 50. So, I can sort the signals like in the following figure (red sektch)
minimum = min(data(data<thres));
locations = find(data(:) == minimum);
Anas Wheba
Anas Wheba el 11 de En. de 2022
Editada: Anas Wheba el 11 de En. de 2022
Thank you sir, but its storing only one number which is 40
Torsten
Torsten el 11 de En. de 2022
Editada: Torsten el 11 de En. de 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.
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.

Iniciar sesión para comentar.

Matt J
Matt J el 11 de En. de 2022
Editada: Matt J el 11 de En. de 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,

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 11 de En. de 2022

Editada:

el 11 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by