How can I make an array with randomly choose from another matrix?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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]
Accepted Answer
KALYAN ACHARJYA
on 23 Apr 2019
Edited: KALYAN ACHARJYA
on 23 Apr 2019
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 Comments
Hang Vu
on 23 Apr 2019
Thank you so much!
KALYAN ACHARJYA
on 23 Apr 2019
Edited: madhan ravi
on 23 Apr 2019
If the question is answered accurately, you can give credit to the answer by accepting it.
Hang Vu
on 23 Apr 2019
Thank you, Do have anyway to put random of B between same number of A? like 1...1 2...2 7...7 9 ....9
KALYAN ACHARJYA
on 23 Apr 2019
Edited: KALYAN ACHARJYA
on 23 Apr 2019
In my answer Its random, Random permutation
As per in your example
for example : C=[1 8 6 1 2 5 3 2 7 11 7 9 10 9]
Do have anyway to put random of B between same number of A? like 1...1 2...2 7...7 9 ....9
That may also possible, I have to figure out. Or you can open the new thred for that issue.
Hang Vu
on 23 Apr 2019
we don't have any way to control their position? in my example, B elements are in between the same number
Hang Vu
on 23 Apr 2019
Thank you for your time! what do you mean by" open new thred'? If it helps me to find the solution, could you please tell me how then!
KALYAN ACHARJYA
on 23 Apr 2019
Edited: KALYAN ACHARJYA
on 23 Apr 2019
New thred menas new Question.
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
on 23 Apr 2019
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!
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)