Matlab Shuffeling Value of Matrix

1 回表示 (過去 30 日間)
wee
wee 2016 年 10 月 7 日
コメント済み: Walter Roberson 2016 年 10 月 9 日
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 件のコメント
KSSV
KSSV 2016 年 10 月 7 日
size of A is 2x30 and B is 3x10 how you expect them to arrange?
Massimo Zanetti
Massimo Zanetti 2016 年 10 月 7 日
I really didn't get it.. Can you put a simple example with small mattrices and vectors?

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2016 年 10 月 7 日
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 件のコメント
wee
wee 2016 年 10 月 9 日
yes, i have answer before
Walter Roberson
Walter Roberson 2016 年 10 月 9 日
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] ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by