How to rewrite matrix ‘Y’ as matrix ‘A’?
Show older comments
Let ‘Y’ be a matrix of ‘N’ rows and ‘T’ columns. How to rewrite matrix ‘Y’ as matrix ‘A’? Where matrix ‘A’ is having ‘N*(T-2)’ rows and ‘((T-1)*(T-2))/2’ columns.
Accepted Answer
More Answers (1)
Andrei Bobrov
on 27 Sep 2016
Edited: Andrei Bobrov
on 28 Sep 2016
EDIT
[m,n] = size(Y);
nn = 1:n;
i0 = triu(nn'*ones(1,n));
i0 = i0(i0 > 0).';
ic = mat2cell(ones(size(i0)),1,nn);
A = repmat(blkdiag(ic{:}),m,1);
[ii,jj] = ndgrid(1:m,i0);
A(A > 0) = Y(sub2ind(size(Y),ii,jj));
Categories
Find more on Logical 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!