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®.
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.
Leave a Reply