Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matrix of matrices in matlab

Tags:

matlab

I need to build up the matrix of matrices. Say, for all $1\leq i,j\leq n$ I have to define a matrix $p_{ij}$ which will be a matrix $n\times n$. What I can do - it is to build up a matrix $P$ which is $n^2\times n^2$ - but for $n=20$ there is an error about memory.

Could you please tell me how to solve this problem?

like image 689
Ilya Avatar asked Dec 28 '22 00:12

Ilya


1 Answers

Use cell arrays. Like this

c = cell(3,3) %Create cell array of size *3x3*

c = 

    []    []    []
    []    []    []
    []    []    []

c{1,1}; = rand(3,3); %Set cell {1,1} to be random matrix of size *3x3*
c{1,2} = ones(4,6)   %Set cell {1,2} to be matrix of ones size *4x6*

c = 

    [3x3 double]    [4x6 double]    []
              []              []    []
              []              []    []

etc..

like image 97
Ghaul Avatar answered Jan 08 '23 23:01

Ghaul