How to rewrite matrix ‘Y’ as matrix ‘A’?
6 views (last 30 days)
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.
0 Comments
Accepted Answer
Thorsten
on 27 Sep 2016
You can also use for-loops:
for j = 1:size(Y, 1)
for i = 1:size(Y,2)
A(i+(j-1)*size(Y,2),(1:i)+sum(1:i-1)) = Y(j,1:i);
end
end
0 Comments
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));
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!