MATLAB: How to randomise numbers in a vector randomvector Dear all, Suppose I have this vector x= [1;2;3;4]; How can I randomise it? (i.e. create different combinations of 1, 2, 3 and 4) Thank you very much in advance, Bianca Best Answer See doc randperm:x = [1;2;3;4]y = x(randperm(numel(x)))If this is time-critical, use FEX: Shuffle . Related SolutionsMATLAB: Shuffle a vector of repeated numbers so the numbers do not repeat Editfam1_1 = [1,1,1,2,2,2,3,3,3,4,4,4] ii=unique(fam1_1)n=numel(fam1_1)m=numel(ii)p=numel(fam1_1)/numel(ii)x=ii(randperm(m))out=xfor k=2:p y=setdiff(ii,x(end)) y1=y(randi(m-1)) y2=setdiff(ii,y1) x=[y1 y2(randperm(m-1))] out=[out x]end MATLAB: How to create a vector with several repetitions of a random permutation x = 1:4;ii = 2;x1 = repmat(x(:)',1,ii);out = x1(randperm(numel(x1))) Related QuestionReplacement of groups of neighbor numbers giving priority to a row-wise checkHow to retain only the rows of a matrix based on the unique numbers in the first column of the matrixHow to surfplot from xyz coordinatesHow I find rows with same elements but in flipped manner.I have two matrices that are related and I need to sort one matrix while sorting the corresponding matrix the same way.Random presentation of the columns of a matrix
Best Answer