フィルターのクリア

Randomly changing a value of a matrix

1 回表示 (過去 30 日間)
Phillip Smith
Phillip Smith 2019 年 11 月 21 日
コメント済み: Phillip Smith 2019 年 11 月 21 日
Hello,
I've made a 5x5 matrix of zeros,
I want to randomly change one of the elements to a 1
How would i go about this?
Many thanks

採用された回答

the cyclist
the cyclist 2019 年 11 月 21 日
編集済み: the cyclist 2019 年 11 月 21 日
M = zeros(5,5);
M(randi(25)) = 1;
This algorithm takes advantage of the power of linear indexing.
  1 件のコメント
Phillip Smith
Phillip Smith 2019 年 11 月 21 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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