Shuffling a vector for n times to generate a new vector

1 回表示 (過去 30 日間)
Shoaibur Rahman
Shoaibur Rahman 2015 年 7 月 22 日
回答済み: Azzi Abdelmalek 2015 年 7 月 22 日
A is a vector. I want to shuffle its elements for n times to generate a new vector. For example:
A = [3 5 1];
out = [Shuffle(A) Shuffle(A) Shuffle(A)] % n = 3, but may be a large value
out =
1 5 3 5 1 3 5 3 1
For a large value of n, I can do it using a loop. But, I was wondering if there was any easy without looping. Thanks.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 22 日
A = [3 5 1]
n=10
a=perms(1:3)'
m=size(a,1)
k=randi(m,n,1)
s=a(:,k)
out=A(s(:))

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by