How Can I randomly select 10% of my array values and replace it with N/A or zero

조회 수: 13 (최근 30일)
Hello Everyone, I hope you are doing well.
I have the dataset 250x1000 attached below. i want to randomly select 10% of element from may array and replace it with N/A or zero. How can i do that in matlab
Any help appreciated :)

채택된 답변

KSSV
KSSV 2022년 2월 26일
편집: KSSV 2022년 2월 26일
Let A be your 250x1000 array.
N = numel(A) ; % total number of elements
idx = randsample(N,round(10/100*N)) ; % select 10% of indices randomly
A(idx) = 0; % replace with 0
  댓글 수: 6
KSSV
KSSV 2022년 2월 26일
It is straight forward, use NaN instead of zeros. Simple.
A(idx) = NaN ; % replace with NaN
KSSV
KSSV 2022년 2월 26일
Read doc, runt he function and you can see the difference.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by