Matlab Shuffeling Value of Matrix

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

size of A is 2x30 and B is 3x10 how you expect them to arrange?
I really didn't get it.. Can you put a simple example with small mattrices and vectors?

Sign in to comment.

Answers (1)

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

no, i need to shuffle values from A(1,:), with the sequences of the same number never be separate
Shuffle A(1,:) and place where?
idx = randperm(30) ;
Arranges the thirty positions randomly.
B = A(:,idx) ;
let's take we will shuffle number 6 6 4 4 4 that have same value in A(1,:) i need they never get this positions from shuffeling
B =
6 6 0 0 0 0 0 0 0 0
4 4 4 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
or
4 4 4 0 0 0 0 0 0
0 6 6 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
or never be on the same B(:, rows) thank you...
Out of 2X30 numbers in A, how many you want to take in B?
You need to show us an arrangement that is permitted as well.
@Dr. Siva Srinivas Kolukula I want shuffle just A(:,1), so just 1X30..and that value will be distributed on B(3X10).is it possible to solve?
or to add any possible positions we can change size B more larger than 3X10, maybe we can improve its size 4X10. All I need is distributed A(:,1) -> 1X10 to matrix B.thank you...
yes, i have answer before
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] ?

Sign in to comment.

Asked:

wee
on 7 Oct 2016

Commented:

on 9 Oct 2016

Community Treasure Hunt

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

Start Hunting!