Professional Documents
Culture Documents
Printing To The Screen
Printing To The Screen
16/12/2022
In MATLAB, there are several ways to print output to the screen. Here are two common
commands for printing to the screen:
The disp function is used to display the value of a variable or an expression to the
screen.
For example, to display the value of a variable x, one can use the following
command:
disp(x)
One can also use the disp function to display the result of an expression, such as:
disp(2 + 3)
The fprintf function is used to display formatted text to the screen. It is similar to the
printf function in C and other programming languages.
For example, to display a string of text to the screen, one can use the following
command:
fprintf('Hello, world!\n')
This will display the string 'Hello, world!' to the screen, followed by a newline character.
One can also use the fprintf function to display the value of a variable or the
result of an expression, along with formatting specifiers. For example:
This will display the string 'The value of x is' followed by the value of x, with
the %d formatting specifier indicating that x is an integer.