フィルターのクリア

How do I create a random row matrix with some fixed positions?

2 ビュー (過去 30 日間)
Abdullah Türk
Abdullah Türk 2019 年 4 月 21 日
コメント済み: Abdullah Türk 2019 年 4 月 21 日
Hello everyone,
I want to create a row matrix with some fixed positions. For example,
>> randperm(20)
ans =
11 3 14 5 4 8 13 15 10 6 18 9 20 16 17 7 12 2 19 1
But I want to keep some positions in this array. For example, the first three positions of the array should always be 11 3 and 14, regardless of how much I use the randperm (20) command. How can I do this? It is possible?

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 4 月 21 日
編集済み: Andrei Bobrov 2019 年 4 月 21 日
a = [ 11 3 14];
b = 1:20;
c = setdiff(b,a);
n = numel(c);
out = [a, c(randperm(n))];
  1 件のコメント
Abdullah Türk
Abdullah Türk 2019 年 4 月 21 日
Thank you vey much Andrei Bobrov.
I've done the process I wanted to do with your coding.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by