Search code examples
arraysmatlabmatrixcell

Using cell array as blocks to build matrix


I have a cell array

matr =

4×1 cell array

    [2×2 double]
    [2×2 double]
    [2×2 double]
    [2×2 double]

I want its elements to build a block matrix such that

A = [matr{1} matr{2} ;
     matr{3} matr{4} ];

But I need this to be generic (i.e. for n number of blocks). I can't figure this out. Is it possible to do it without loops?


Solution

  • Have you tried the reshape function? Something like:

    A = cell2mat(reshape(matr,2,2)'