Matrices like member of matrices

I have matrice T = [a,b;c,d]. Now I need to put matrice inside matrice.
For example I want for a to be a = [1,2,3,4].
How to solve this?
Thank you uvery much in advanced.

Answers (2)

If the matrices are different sizes/classes or you want a simply way to index you could use a cell array:
%four different this
a = [1 2 3 4];
b = magic(3);
c = pi;
d = 'hello world';
T = {a,b;c,d}; %build cell
To extract the contents use curly braces {} and the index as you would with a normal array:
T{2,2}
Or maybe you want something like this?
a = magic(3);
b = eye(4);
c = ones(2);
d = blkdiag(a,b,c); % Puts the input matrices along the diagonal, block by block.
d(1:2,8:9) = [1, 2; 3, 4]; % Insert smaller matrix into correctly-sized area of bigger matrix.

Categories

Asked:

on 19 Jan 2012

Community Treasure Hunt

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

Start Hunting!