Matlab

How to Display a String with Matrix in MATLAB

MATLAB is a useful tool in science and engineering used for performing operations on matrices and strings. In MATLAB, we can display the strings with a matrix by using the disp() function. This article is going to explore how to display the string with a matrix in MATLAB using some examples.

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:

disp(name of a variable) or disp(‘text as string’)

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.

A = [1 2 3; 4 5 6; 7 8 0];
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.

disp('The matrix A is')
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.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.