Search array for largest value of the desired format

7 ビュー (過去 30 日間)
lightroman
lightroman 2017 年 11 月 8 日
編集済み: lightroman 2017 年 11 月 8 日
I have an array, data, I need to search through it to find 1000 , 2000 , 3000 , ... n
As many as exist in the array. 1000 will always exist and 32000 is the highest.
output should be 1 if just 1000, 2 if 1000 and 2000, 3 if 1000 2000 and 3000 exist in the array, data.
I can figure it out with a while and nested for loop but its too inefficient for what i am attempting to do.

採用された回答

KL
KL 2017 年 11 月 8 日
編集済み: KL 2017 年 11 月 8 日
Something like,
A = [1 2 1000 3 4 2000 4 3 3000];
B = (1:10)*1000;
res = nnz(ismember(A,B));
and if there are more than one of 1000/2000/etc, the value of res will be subsequently be higher.
  1 件のコメント
lightroman
lightroman 2017 年 11 月 8 日
編集済み: lightroman 2017 年 11 月 8 日
well 1000 can increase all the way to 32000 but really just any multiple of 1000.
Sorry that little detail was hard to read in 1000,2000,3000,....
EDIT: got it actually this will work thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by