フィルターのクリア

How can I make 80 percent of the matrix values equal to zeros, randomly?

11 ビュー (過去 30 日間)
Khan
Khan 2021 年 6 月 28 日
コメント済み: KSSV 2021 年 6 月 28 日
I have a matrix A (30 by 20). I want to generate three random matrices, each containing 20 percent of the orgional matrix. In other words, I want to replace 80 percent values of A matrix to zeros but randomly. Thank you

採用された回答

KSSV
KSSV 2021 年 6 月 28 日
編集済み: KSSV 2021 年 6 月 28 日
A = rand(30,20); % Matrix for demo
B = A ;
idx = randperm(numel(A),round(numel(A)*80/100)) ; % get 80% of indices randomly
B(idx) = 0 ; % replace with zero
  2 件のコメント
Khan
Khan 2021 年 6 月 28 日
Thank you so much and How can I save it as a new matrix?
KSSV
KSSV 2021 年 6 月 28 日
Edited the answer.

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

その他の回答 (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