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
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
2022년 1월 11일
0 개 추천
You are not using the loop variable i anywhere.
댓글 수: 12
Anas Wheba
2022년 1월 11일
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
2022년 1월 11일
Anas Wheba
2022년 1월 11일
That would just be,
data=[2 3 5 2 7];
locations= find( data(:)==min( data(:) ) )
Anas Wheba
2022년 1월 11일
Anas Wheba
2022년 1월 11일
Torsten
2022년 1월 11일
minimum = min(data(data<thres));
locations = find(data(:) == minimum);
Anas Wheba
2022년 1월 11일
편집: Anas Wheba
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
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 Exchange에서 Electrophysiology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

