If condition for a large number of different numbers

3 ビュー (過去 30 日間)
Filippos Papasavvas
Filippos Papasavvas 2018 年 8 月 11 日
回答済み: Ameer Hamza 2018 年 8 月 11 日
Hi!
I have a long array of random values [1 2 4 5 6 2 1 .....]. I take the maximum of the array and get an index value eg 50 for the position of the maximum value. I want if the index value = 1 or 1+kz or 1+2*kz, 1+3*kz,...,1+1000*kz (where kz is some natural number) to write the value of 1 in a new vector. If index value = 2 or 2+kz or 2+2*kz, 2+3*kz,...,1+1000*k I want to write the value 2 in a new vector. Due to the amount of values I'd prefer not to have to write explicitly each one of them in an 'if ...or...' form. I hope I explained this well.
Thanks for any help! Filippos

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 8 月 11 日
max() function returns both maximum value and its index.
[value, index] = max(array);
For the second part about 1+kz can you give a numeric example on a small vector.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by