MATLAB Answers

Myrtle42
0

Combine two cell arrays into a block diagonal array

Asked by Myrtle42
on 10 Feb 2018
Latest activity Answered by Walter Roberson
on 10 Feb 2018
The function blkdiag can be used to combine two numerical arrays with different dimensions into a block diagonal matrix, with 0s in the missing locations. Is there anything similar for two cell arrays, where the missing elements would just be empty cells? (I could do it manually, just wondering if there is a built-in function to keep my code clean as with blkdiag). Thanks!

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 10 Feb 2018

n = numel(YourCell);
out = cell(n, n);
out(1:n+1:end) = YourCell;

  0 Comments

Sign in to comment.