How can I make an array with randomly choose from another matrix?

조회 수: 3 (최근 30일)
Hang Vu
Hang Vu 2019년 4월 23일
댓글: Hang Vu 2019년 4월 23일
A=[1 2 7 9] => how to build A like this> A=[1 1 2 2 7 7 9 9]
B=[3 5 6 8 10 11] : randomly choose all items from Band input between 2 same number of A
for example : C=[1 8 6 1 2 5 3 2 7 11 7 9 10 9]

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 23일
편집: KALYAN ACHARJYA 2019년 4월 23일
First One:
A=[1 2 7 9] => how to build A like this> A=[1 1 2 2 7 7 9 9]
result=repelem(A,2)
2nd One:
>> A=[1 2 7 9];
>> B=[3 5 6 8 10 11];
>> c1=[A,B];
>> C=c1(randperm(10))
%.................^.....length Required
C =
5 1 6 9 10 3 8 7 11 2
Or Check here
>> A=[1 2 7 9];
>> A=repelem(A,2)
A =
1 1 2 2 7 7 9 9
>> B=[3 5 6 8 10 11];
>> c1=[A,B];
>> C=c1(randperm(length(c1)))
C =
8 1 11 5 10 9 3 1 7 6 9 7 2 2
  댓글 수: 8
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 23일
편집: KALYAN ACHARJYA 2019년 4월 23일
New thred menas new Question.
I have already seen you have posted the new question, with specific pattern.
I will try to answer, if I can generate that C Pattern from v1,v2,v3,v4
As I got the logic of pattern generation of C from v1,v2,v3,v4.
If Time allow I will answer as earliest on that section, or you may get the answer from others members.
Ley see..
Hang Vu
Hang Vu 2019년 4월 23일
Thank you so much sir! This is just my idea, I don't know if it's possible. I will also try to solve it and looking forward for your way!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by