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 件のコメント

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 日

0 投票

You are not using the loop variable i anywhere.

12 件のコメント

Anas Wheba
Anas Wheba 2022 年 1 月 11 日
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
Torsten
Torsten 2022 年 1 月 11 日
"(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 ?
Anas Wheba
Anas Wheba 2022 年 1 月 11 日
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
Anas Wheba
Anas Wheba 2022 年 1 月 11 日
i want to find multiple minium values then store them in an array
Matt J
Matt J 2022 年 1 月 11 日
編集済み: Matt J 2022 年 1 月 11 日
That would just be,
data=[2 3 5 2 7];
locations= find( data(:)==min( data(:) ) )
locations = 2×1
1 4
Anas Wheba
Anas Wheba 2022 年 1 月 11 日
I tried it but it did not work, its the same with what i wrote
Torsten
Torsten 2022 年 1 月 11 日
編集済み: Torsten 2022 年 1 月 11 日
It does not work because of your if-statement before. See my comment above.
And the loop is not necessary.
Anas Wheba
Anas Wheba 2022 年 1 月 11 日
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)
Torsten
Torsten 2022 年 1 月 11 日
minimum = min(data(data<thres));
locations = find(data(:) == minimum);
Anas Wheba
Anas Wheba 2022 年 1 月 11 日
編集済み: Anas Wheba 2022 年 1 月 11 日
Thank you sir, but its storing only one number which is 40
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,

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

質問済み:

2022 年 1 月 11 日

編集済み:

2022 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by