필터 지우기
필터 지우기

How to Shuffle some arrays of a matrix? (permutataion matrix considered)

조회 수: 1 (최근 30일)
for shuffling I have this codes so far
nVar=length(x);
cc=randsample(nVar,2);
c1=min(cc)
c2=max(cc)
now I need to shuffle arrays between C1 and C2 without having a number twice. each number has to appear only once
  댓글 수: 2
Adam
Adam 2014년 8월 12일
What do you expect to happen to the data outside of the C1 to C2 range? Are the arrays in question ordered so that data between C1 and C2 will always be contiguous and everything else in the array stays where it is?
The 'unique' function will get rid of duplicates for you.
alexaa1989
alexaa1989 2014년 8월 12일
I need arrays between c1 and c2 shuffle randomly and appear once and everything outside C1:C2 stays the same as before

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 8월 12일
n = numel(x);
c = sort(randsample(nVar,2));
r = c(1)+1:c(2)-1;
z = x(r);
x(r) = z(randperm(diff(c)-1));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by