Seperate One Matrix into two!!
1 view (last 30 days)
Show older comments
Say, I have a matrix
a = [1 2 3 4 5 6 7 8 9 10]
randsel = randperm (10,5)
Say randsel returns [1 3 5 6 10]
Now, I want to select the rest of the numbers and put it into another matrix ,say 'randsel2'
How to do that??!
0 Comments
Accepted Answer
Stephen23
on 8 Nov 2015
Edited: Stephen23
on 8 Nov 2015
If you generate all of the indices using randperm, then you can simply select the first half of those indices and the second half: these are all random indices, so the two selections are also random.
>> a = 20:29 % twenties to distinguish from the indices.
a =
20 21 22 23 24 25 26 27 28 29
>> idx = randperm(10); % generate all indices
>> a(idx(1:5)) % first half of random indices to select one set
ans =
29 28 25 21 20
>> a(idx(6:end)) % second half of random indices to select reamining
ans =
22 27 26 23 24
1 Comment
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!