Logo white

codebase / stim-matlab

Sign in
  • Sign in
  • Project
  • Files
  • Commits
  • Network
  • Graphs
  • Milestones
  • Issues 0
  • Merge Requests 0
  • Labels
  • Wiki
  • stim-matlab
  • rtsRandomizeMask.m
  • initial commit of the new Matlab repository
    8be1ab93
    David Mayerich authored
    2015-04-07 13:24:08 -0500  
    Browse Code ยป
rtsRandomizeMask.m 368 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
function R = rtsRandomizeMask(mask, N)

%error checking
if N > nnz(mask)
    N = nnz(mask);
end

if N < 0
    N = 0;
end

%get the indices of all nonzero values in the mask
ind = find(mask);

%randomize the indices
rind = ind(randperm(size(ind, 1)));

%create the new randomized mask (random subset of the old mask)
R = zeros(size(mask));
R(rind(1:N)) = 1;

R = R > 0;