MATLAB: Create a subset of data matrix randomly

random

i have a complete matrix of dimension 116X17. I need a half of the elements ie 896 elememens of the matrix are created randomly with all other cell have NaN value.

Best Answer

A = rand(116,17) ; % your data
N = 896 ;
iwant = NaN(size(A)) ;
idx = randperm(numel(A),N) ;
iwant(idx) = A(idx) ;