How Can I randomly select 10% of my array values and replace it with N/A or zero
12 次查看(过去 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 :)
0 个评论
采纳的回答
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
2022-2-26
It is straight forward, use NaN instead of zeros. Simple.
A(idx) = NaN ; % replace with NaN
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!