필터 지우기
필터 지우기

Insertion of the index

조회 수: 2 (최근 30일)
Bathrinath
Bathrinath 2013년 12월 18일
편집: Andrei Bobrov 2013년 12월 18일
The number of jobs n =4 which are in k = [3,2,4,6].
First index value in k is 3, now i need to insert the first index value to second index value which is k1 = [2,3,4,6]. From k,first index value is inserted to the third index value k2 = [2,4,3,6]. From k, first index value is inserted to fourth index value k3 = [2,4,6,3]. Now the first index process is over. Select the second index form k and insert the values in different position. k4 = [2,3,4,6]; k5 = [3,4,2,6]; k6= [3,4,6,2].
Select the third index from k and insert the values in different position. k7 = [4,3,2,6]; k8= [3,4,2,6]; k9 = [3,2,6,4].
Select the fourth index from k and insert the valued in different position. K10 = [6,3,2,4]; k11 = [3,6,2,4]; k12 = [3,2,6,4].
This process has to be repeated with respect to the number of jobs.

채택된 답변

Roger Stafford
Roger Stafford 2013년 12월 18일
Here's a way using two nested for-loops:
K = zeros(n*(n-1),n);
r = 0;
for i1 = 1:n
p = [1:i1-1,i1+1:n];
for i2 = p
r = r + 1;
K(r,:) = k([p(1:i2-1),i1,p(i2:n-1)]);
end
end
The rows of K are your k1, k2, k3, ...,
  댓글 수: 1
Bathrinath
Bathrinath 2013년 12월 18일
Thanks sir its working fine

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 12월 18일
편집: Andrei Bobrov 2013년 12월 18일
n =4;
k = [3,2,4,6];
i1 = repmat((1:n)',1,n);
p = i1.*~eye(n)+triu(ones(n));
i3 = rem(bsxfun(@plus,reshape(0:n-1,1,1,[]),p)-1,n)+1;
i02 = reshape(i3,n,[])';
i02((1:n:size(i02,1)) + (0:n-1),:)=[];
out = k(i02);

카테고리

Help CenterFile Exchange에서 MATLAB Parallel Server에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by