필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by