npermutek

버전 1.0.2 (1.45 KB) 작성자: Syed Faheemuddin
permutes k elements from the vector v
다운로드 수: 818
업데이트 날짜: 2018/11/23

라이선스 보기

NPERMUTEK - permutations without repetitions.
This function A = npermutek(v,k) returns all the possible permutations
of k elements from the vector v without repetitions. k should be less than
or equal to number of elements in v.
The function [A, I] = npermutek(v,k) returns both the matrix and indeces
of the permuted matrix, such that A = v(I). Both matrices will be of the
size nPk-by-k where k = numel(v).

Examples:

v = 1:4;
k = 3;
A = npermutek(v,k); % returns 24-by-3 matrix
1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2

v = 'abc';
k = 2;
[A,I] = npermutek(v,k) % returns 6-by-2 char array

'ab'
'ac'
'ba'
'bc'
'ca'
'cb'

and 6-by-2 matrix

1 2
1 3
2 1
2 3
3 1
3 2

인용 양식

Syed Faheemuddin (2024). npermutek (https://www.mathworks.com/matlabcentral/fileexchange/69507-npermutek), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2018b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.2

Corrected some spelling mistakes

1.0.1

Just spelling mistakes

1.0.0