pradeep kumar Tarei
pradeep kumar Tarei

Reputation: 83

Formation of a BIGGER matrix from n numbers of smaller matrix

I have obtained few matrices by for-loop.
Say for example m1(for i=1)=[1 ; 2 ; 3], m2(for i=2)=[4 ;5 ; 6], m3(for i=3)=[7; 8 ; 9] and so on.
Now I want to form a bigger matrix, M, from the elements of m1, m2, m3 and so on:

M=[0 0 0 1 - - ;
   0 1 4 7 - - ;
   0 2 5 8 - - ;
   0 3 6 9 - - ;
   0 0 0 0 - - ]  

M is a very big dimension (m x n) matrix and each column of M represents a mi matrix and some of its specific column will be zero (null matrix).
How can I efficiently achieve this?

Upvotes: 0

Views: 85

Answers (2)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

I think the best way here would be to store them in a big matrix directly.

Example:

M = zeros(5,4)
for i = 1:size(M,2)
   M(i,:) = [0 1 2 3]
end

Upvotes: 2

ServerS
ServerS

Reputation: 450

Try this, I think it is what you want:

M = [m1;m2;m3];

Upvotes: 1

Related Questions