Skip to Main Content
Programming in MATLAB ®: A Problem-Solving Approach by Pearson
book

Programming in MATLAB ®: A Problem-Solving Approach by Pearson

by Ram N. Patel, Ankush Mittal
May 2024
Intermediate to advanced content levelIntermediate to advanced
433 pages
13h 7m
English
Pearson India
Content preview from Programming in MATLAB ®: A Problem-Solving Approach by Pearson
30
Ñ
Matrix Operations and Applications
You can create a diagonal matrix with the given elements by using the diag command as follows:
>> d = [1 3 5 7], A = diag(d)
d =
1 3 5 7
A =
1 0 0 0
0 3 0 0
0 0 5 0
0 0 0 7
Many times, special matrices are required for testing your functions. One command that is
frequently used in such cases is magic. The magic function creates a square matrix in which
the sum of elements in all columns and rows and the two diagonals are equal. Consider the fol-
lowing example:
>> z = magic(3) % gives the following matrix
z =
8 1 6
3 5 7
4 9 2
2.4.4 Concatenation
Larger matrices can be formed by concatenating smaller matrices. The pair of square brackets,
[ ], is also known as the concatenation operator. The basic idea behind ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Applied Numerical Methods Using MATLAB, 2nd Edition

Applied Numerical Methods Using MATLAB, 2nd Edition

Won Y. Yang, Wenwu Cao, Jaekwon Kim, Kyung W. Park, Ho-Hyun Park, Jingon Joung, Jong-Suk Ro, Han L. Lee, Cheol-Ho Hong, Taeho Im
MATLAB Recipes: A Problem-Solution Approach

MATLAB Recipes: A Problem-Solution Approach

Michael Paluszek, Stephanie Thomas
Practical MATLAB Deep Learning: A Projects-Based Approach

Practical MATLAB Deep Learning: A Projects-Based Approach

Michael Paluszek, Stephanie Thomas, Eric Ham

Publisher Resources

ISBN: 9781306983440Publisher Website