Make r a 1x5 vector using rand. Find the elements that have values <0.5 and set those values to 0 (use find).

9 ビュー (過去 30 日間)
Confused on how to write this code,
r = rand(1,5); find(r<0.5)=0
tried that, didnt work. anything help. Thanks in advance!

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 18 日
idx = find(r<0.5);
Now think about r(idx)
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 18 日
find does not return values, find returns locations, also known as indices, which is often abbreviated to idx in English (because the singular of "indices" is "index")

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by