Combine two cell arrays into a block diagonal array

3 次查看(过去 30 天)
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!

回答(1 个)

Walter Roberson
Walter Roberson 2018-2-10
n = numel(YourCell);
out = cell(n, n);
out(1:n+1:end) = YourCell;

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by