Advertisement
Guest User

Efficient MxN

a guest
Oct 15th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. % Much more efficient MxN:
  2. % Note, we rotate the matrix here so rows and columns are also swapped,
  3. % this is because the reshape function reads column-wise.
  4. % Uses combn function:
  5. % http://www.mathworks.com.au/matlabcentral/fileexchange/7147-combn-4-3
  6.  
  7. n = 2; % number of rows
  8. m = 3; % number of columns
  9. num_list = [0 1 2]; % List of numbers to choose from.
  10.  
  11. num_com = size(num_list,2) .^ (m*n); %Total number of combinations
  12.  
  13. output = mat2cell(reshape(combn(num_list, m*n)', n, m*num_com), n, repmat(m,1,num_com));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement