필터 지우기
필터 지우기

pseudorandomise vectors in an array

조회 수: 1 (최근 30일)
Doug Barrett
Doug Barrett 2013년 4월 25일
I'd like to pseudorandomise vectors in an array to produce all possible combinations of an initial sequence without repetition. For example, a 2x2 array containing combinations of -1 and 1 would be [-1 1; 1 -1]. A 4x4 array of the same values would be [-1 -1 1 1; 1 -1 1 -1; -1 1 -1 1; 1 1 -1 -1].
I can evaluate equality using 'isequal' and shuffle elements on a vector or array basis using 'reshape(randperm(numel(array)), size(array))' but I'm not sure how to do this iteratively to psuedorandomise the elements in each vector.
Any help or advice would be much appreciated!
Doug.

채택된 답변

Craig Cowled
Craig Cowled 2013년 4월 25일
Doug, I use a function that was developed by Jos, called allcomb. You can find it at the following link http://www.mathworks.com.au/matlabcentral/fileexchange/10064-allcomb.
This function has one drawback though. allcomb will give you all possible combinations, including repetitions. You could use this function to find all possible combinations, then write your own code to eliminate repetitions.
I have used allcomb to populate an array containing all possible combinations, then I applied a test to identify repeats and eliminated these results from the array.
I hope this helps.
  댓글 수: 1
Doug Barrett
Doug Barrett 2013년 4월 26일
Craig, thanks for pointing me in the right direction, I've used another of Jos' functions, 'combn', which outputs all the possible permutations of my ([-1 1],n) vector.
In terms of eliminating repeats, I've just found 'unique', which is very handy Matlab function for the job!
Doug.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by