Home > utils > rand_order_no_repeats.m

rand_order_no_repeats

PURPOSE ^

randomizes the order of the input_vector and attempts to not allow any one

SYNOPSIS ^

function [output_vector, vector_ind] = rand_order_no_repeats(input_vector)

DESCRIPTION ^

 randomizes the order of the input_vector and attempts to not allow any one
 value to be repeated in consecutive order (assuming that there are repeats
 in the values). Note that this won't be possible if the number of occurrences
 of any one value is greater than round(length(vector_ind)/2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [output_vector, vector_ind] = rand_order_no_repeats(input_vector)
0002 % randomizes the order of the input_vector and attempts to not allow any one
0003 % value to be repeated in consecutive order (assuming that there are repeats
0004 % in the values). Note that this won't be possible if the number of occurrences
0005 % of any one value is greater than round(length(vector_ind)/2)
0006 
0007 rand('state',sum(100*clock));
0008 
0009 rand_input_vector = input_vector(randperm(length(input_vector)));
0010 unique_values = unique(rand_input_vector);
0011 
0012 for(idx = 1:length(unique_values))
0013   vals(idx).value = unique_values(idx);
0014   vals(idx).order = find(rand_input_vector == vals.value);
0015   vals(idx).repeats = find(vals(idx).order == vals(idx).order+1);
0016 end
0017 
0018 
0019 
0020 %now do the work of checking for consecutive values and reorder appropriately
0021 for(unique_idx = 1:length(unique_values))
0022   
0023   if(~isempty(vals(unique_idx).repeats))
0024     
0025     for(swap_idx = setdiff([1:length(unique_values)],unique_idx))
0026       
0027       for(repeat_idx = vals(unique_idx).repeats)
0028     
0029     if(
0030     
0031     
0032     
0033     
0034       end
0035       
0036       
0037       
0038       
0039       
0040     end
0041     
0042     
0043     
0044   
0045   end
0046   
0047 end

Generated on Sun 24-Mar-2019 04:00:51 by m2html © 2003