How do you replace duplicate values in an array?

1 回表示 (過去 30 日間)
Vy-An
Vy-An 2014 年 6 月 24 日
回答済み: José-Luis 2014 年 6 月 24 日
I'm trying to create an array (1 by n) filled with random integers. All of the integers have to be unique. I tried using unique but that only got rid of the duplicate values and shortens the array; I want to keep my array at a constant size. How can I replace these duplicate values, without affecting the others?
example:
[ 1 3 5 5 6 7 9 9 ]
turns into
[ 1 3 5 8 6 7 9 2 ]
or something like that (5 and 9 are replaced).
Or, better yet, is there any random function that doesn't repeat at all? Thanks.

採用された回答

José-Luis
José-Luis 2014 年 6 月 24 日
randperm(9,9)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by