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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by