How to rewrite matrix ‘Y’ as matrix ‘A’?

6 views (last 30 days)
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

Thorsten
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

More Answers (1)

Andrei Bobrov
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
SAGAR MATUR
SAGAR MATUR on 27 Sep 2016
I am getting this error: "??? Error using ==> sub2ind at 52 The subscripts vectors must all be of the same size." in MATLAB version R2011a

Sign in to comment.

Categories

Find more on Programming 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!