Matlab Shuffeling Value of Matrix
1 view (last 30 days)
Show older comments
I have a 3 x 10 matrix, B zeros(3,10) I need to shuffle this value A(1,:) in matrix B
A = [6 6 4 4 4 1 1 3 3 5 5 2 2 2 7 7 9 9 9 8 8 8 11 11 11 12 12 13 13 13;
1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5
set x = length of sequences with same value in A(1,:)
A(1,:) with the same value in A(2,:) can be place at the same B(:,1:x) thank you so much...
2 Comments
Massimo Zanetti
on 7 Oct 2016
I really didn't get it.. Can you put a simple example with small mattrices and vectors?
Answers (1)
KSSV
on 7 Oct 2016
A = rand(3,30) ;
B = zeros(3,10) ;
%%Random 10 picks out of 30
pos = 1:size(A,2) ;
idx = randsample(pos,10) ;
B = A(:,idx) ;
Are you expecting like this?
10 Comments
Walter Roberson
on 9 Oct 2016
Given an input A, and a candidate output matrix B, how can we tell if B is not a permitted output?
Oh wait... you wrote "with the sequences of the same number never be separate". So does that mean that for your input
A = [6 6 4 4 4 1 1 3 3 5 5 2 2 2 7 7 9 9 9 8 8 8 11 11 11 12 12 13 13 13;
1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5]
that the first [6 6] needs to appear as a block in the output, and the [4 4 4] needs to appear as a block in the output, and the [1 1] needs to appear as a block, and so on, but that the [4 4 4] from the first row of A does not need to be immediately beside the [4 4 4 4 4 4 4 4] from the second row of A, just because those are distinct blocks?
I notice in your sample input that the same number does not appear in two different blocks in the first row, and also that the same number does not appear in two different blocks in the second row. Will that always be true?
Do the blocks from the first row need to appear "above" all of the blocks from the second row? Do they need to appear "above" the block of the same value from the second row? Would it be permitted for the [1 1] block from the first row to appear below the [1 1 1 1 1] block from the second row? Would it be permitted to have the two beside each other, [1 1 1 1 1 1 1] ?
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!