Create diagonals along a block matrix
1 view (last 30 days)
Show older comments
Good Morning,
I have a 4x4 matrix containing values only in the first column and all 0's in the remaining spaces. The values contained in each cell are actually vectors of multiple values.
I'd like to make the first value (vector) of the first row be carried over to the second row of the second column, the third row of the third column, and so on. I would like to do the same for the second value (vector) of the first row, which should be reported in the third row of the second column, and so on, in order to create diagonals along the matrix containing the same values.
How can I do this?
Thank you so much!!
Accepted Answer
Jan
on 15 Dec 2021
Edited: Jan
on 15 Dec 2021
With some bold guessing and knowing, that this might be more confusing than useful:
The input A is a cell vector and the wanted output B a cell matrix:
A = {[0,0]; ...
[1,1]; ...
[2,1]; ...
[3,3]};
H = flipud(hankel(4:-1:1)) % The display is cropped:
B = cell(numel(A), numel(A));
B(H ~= 0) = A(H(H~= 0))
% Or maybe:
H2 = max(1, flipud(hankel(4:-1:1))) % The display is cropped:
B2 = A(H2)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!