How to rewrite matrix ‘Y’ as matrix ‘A’?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SAGAR MATUR
am 27 Sep. 2016
Bearbeitet: Andrei Bobrov
am 28 Sep. 2016
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 Kommentare
Akzeptierte Antwort
Thorsten
am 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 Kommentare
Weitere Antworten (1)
Andrei Bobrov
am 27 Sep. 2016
Bearbeitet: Andrei Bobrov
am 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 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!