# How to compare a value to a matrix and repeat the comparison after increasing the value

4 ビュー (過去 30 日間)
Ahmed Makki 2020 年 6 月 13 日
コメント済み: Ahmed Makki 2020 年 6 月 17 日
I am working on an algorithm that compare the vectors' peak locations with the average vector peak location and excluding vectors that their peaks are located over 10 Hz away from the average vector. The average vector peak then it will be included otherwise if the number of vectors included is less than 20 vectors then I should increase the difference in peak location by 10 Hz until it reaches or exceeds 20.
I am not able to create a loop that recompare (RA is the difference between peak locations in Hz) the peaks after increasing V from 10 Hz by 10 Hz every time until the number of vectors I1>=I.
Can you please help me create a loop the recompare RA with V (for k = find(RA<=V))
V=10; I=20; I1=0;
for k = find(RA<=V);
if numel(k)>=I
RI=RV(:,k); I1=numel(k);
elseif I1<I
V=V+10;
else
break;
end
end
end
##### 2 件のコメント表示非表示 1 件の古いコメント
Ahmed Makki 2020 年 6 月 17 日
In a simpler way, for a given values of A and B. If [array]<=B and if the number of elements in the array that satisfy this condition are equal or greater than A then y=x+1 else increase B by 1 and recompare it with the array elements until both conditions apply.

サインインしてコメントする。

### 採用された回答

Anmol Dhiman 2020 年 6 月 17 日
Hi Ahmed,
while(1)
% find number of elements that satisfy [array]<=B
numOfElements = length(find(array<=B));
% Check if they are greater than A
if(A<=numOfElements)
y=x+1;
break;
else
B=B+1;
end
end
##### 1 件のコメント表示非表示 なし
Ahmed Makki 2020 年 6 月 17 日
It worked thank you very much for your help

サインインしてコメントする。

### その他の回答 (1 件)

Steven Lord 2020 年 6 月 16 日
Do you want to find the candidate peaks using islocalmax then select those candidates that are within 10 of your average?
##### 1 件のコメント表示非表示 なし
Ahmed Makki 2020 年 6 月 17 日
Thank you. I know how to determine the peaks locations, but the problem is in creating a loop that increases the number that we compare with until it satisfy conditions. Please find above a clearer discription of the problem that made

サインインしてコメントする。

### カテゴリ

Find more on Logical in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by