Home » All Programs » Combining Two Or More Matrices Into One Matrix In MatLab®(Illustrated Expression)

Combining Two Or More Matrices Into One Matrix In MatLab®(Illustrated Expression)

Matrices and matrix calculations are very important things in Linear Algebra and conventional mathematics. Matlab® has lots of commands to ease these matrix calculations. In some cases, you need to combine various matrices into one matrix to make your calculation in Matlab®. So it is a very basic process to do it in Matlab®.

MATLAB For Beginners: A Gentle Approach

If you are interested to learn MATLAB® at an engineering level, click on the given link or the ‘Shop Now’ button to check the recommended book by Mechanicalland, from Amazon!

How To Combine Different Matrices Into One Matrix In Matlab® Programming?

>> a = [eye(3) rand(3)]
b = [eye(3); ones(1, 3)]

a =

  Columns 1 through 5

   1.000000000000000                   0                   0   0.814723686393179   0.913375856139019
                   0   1.000000000000000                   0   0.905791937075619   0.632359246225410
                   0                   0   1.000000000000000   0.126986816293506   0.097540404999410

  Column 6

   0.278498218867048
   0.546881519204984
   0.957506835434298


b =

     1     0     0
     0     1     0
     0     0     1
     1     1     1

>> 

We created a matrix called ‘a’ that is the combination of two matrices; a 3×3 eye matrix and a 3×3 random element matrix. These matrices are combined as a row basis because there is no semicolon between them at ‘a’. The row number of them must be equal to do this kind of combination, so there is no problem with the combination of them in Matlab®.

To combine the matrices, just type them as a vector, and assign them to the variables.

Also, two matrices are combined into ‘b’ matrix as shown above; one of hem 3×3 eye matrix and one of them 1×3 ones matrix. As you can see, they combined on a columnar basis, because there is a semicolon between combined matrices at ‘b’. Column numbers of eye and ones matrices are equal, so there is no problem with the combination of them.

You can see the result of combinations as shown above in Matlab®.

Conclusion

So it is very easy to combine two or more matrices into one matrix in Matlab®.

Do not forget to leave your comments and questions below about combining two or more matrices into one matrix in Matlab® below. 

If you want further coding examples about combining two or more matrices into one matrix in Matlab®, inform us in the comments.

This article is prepared for completely educative and informative purposes. Images used courtesy of Matlab®

Your precious feedbacks are very important to us.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Please

leave feedback ?

( For the post )

ASK THE MECHANICALLAND

COMMUNITY


We are always open to your feedback to improve ourselves and the quality of our content! If you have any suggestions, thoughts, or criticism, please let us know. We are trying to improve our blog with constructive feedback. We are aware of how valuable your feedback is for our future development, and we will carefully read all your comments. Thank you in advance!