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

1 回表示 (過去 30 日間)
alexaa1989
alexaa1989 2014 年 8 月 12 日
コメント済み: omar A.alghafoor 2020 年 10 月 10 日
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));
  2 件のコメント
alexaa1989
alexaa1989 2014 年 8 月 12 日
Thank you so much it worked
omar A.alghafoor
omar A.alghafoor 2020 年 10 月 10 日
how inverse shuffling for above code

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by