How to Display a String with a Matrix in MATLAB?
We can display a string with a matrix in MATLAB by using the disp() function in MATLAB. The disp() is a built-in function in MATLAB that allows us to print a string or a value of the variable without printing its name. This is a useful tool that can also print a vector, a matrix, or an array without printing their names. This function can also be utilized for printing the string with a matrix. The function follows a simple syntax that is given below:
Examples
Let’s consider several examples for understanding how to utilize the string with a matrix in MATLAB.
Example 1
This example uses the disp() function to display the string with a matrix.
disp('Elements of a Matrix A are:')
disp(A)
Example 2
This MATLAB code uses the disp() function to display the string with a matrix.
A = [1 2 3; 4 5 6; 7 8 0];
disp(A)
disp('The matrix B is')
B = magic(3);
disp(B)
disp('Sum of matrix A and the matrix B is:')
C = A+B;
disp(C)
Conclusion
MATLAB is a useful tool in science and engineering used for performing operations on matrices and strings. The disp() function in MATLAB can be used for displaying a string with a matrix. The disp() is a built-in function in MATLAB that prints a string or a value of the variable without printing its name. This tutorial taught us how to display a string with a matrix in MATLAB using the disp() function.