矩阵A:
A=[1 2 3;
1 3 4;
4 5 6]
矩阵R:
R=[1 1 2 2 3 3 4 4 5 5 6 6;
1 1 2 2 3 3 4 4 5 5 6 6 ]
新矩阵是:
New=[1 1 2 2 3 3;
1 1 2 2 3 3;
1 1 3 3 4 4;
1 1 3 3 4 4;
4 4 5 5 6 6;
4 4 5 5 6 6 ]
任何想法?
答案 0 :(得分:1)
我假设您的矩阵R
定义如下:
R = [1 1 2 2 3 3 4 4 5 5 6 6 ;
1 1 2 2 3 3 4 4 5 5 6 6 ]
使用索引矩阵A
A = [ 1 2 3;
1 3 4;
4 5 6 ]
%// clustersize in R
c = [2 2]
%// clustered R
Rx = mat2cell(R,c(1),repmat(c(2),size(R,2)/c(2),1));
%// or more direct
%// Rx = mat2cell(R,2,[2 2 2 2 2 2]);
%// indexing of Rx with A and decollapsing of cell
out = cell2mat( Rx(A) )
out =
1 1 2 2 3 3
1 1 2 2 3 3
1 1 3 3 4 4
1 1 3 3 4 4
4 4 5 5 6 6
4 4 5 5 6 6