# Displaying Expressions In MatLab With fprintf() Command(Illustrated Expression)

Matlab provides various kinds of demonstration codes and options to user to display their variables and expressions in Command Window. This is very useful thing for the users of the created code. One of these ways to demonstrate the variables or expressions in Matlab is fprintf() command. In this article we will explain the use of fprintf() command in Matlab.

### How To Use fprintf() Command In MatLab?

We simply created a variable ‘t’ to represent the temperature value. The use of fprintf() command is like above that you need to type the expression first as ‘expression = %2.1’, then the variable that you want to display directly after a comma as shown by red arrow above.

You can define the demonstration of the variable inside the expressions as above. The codes inside the expressions such as = %2.1f means that;

%2.1f; show the variable as two integer number and one decimal number after comma(2.1). ‘f’ expression means that show the number or variable directly as shown by red box above.

%2.1e; show the variable as two integer number and one decimal number after comma(2.1). ‘e’ expression means that show the number or variable as in scientific format as shown by green box above.

%2.1g; show the variable as two integer number and one decimal number after comma(2.1). ‘g’ expression means that show the number or variable as in exponential format as shown by red box above.

If you do not use ‘\n’ at fprintf command in Matlab, the whole expressions will be displayed as above. We used ‘\n’, and the expressions are displayed regularly in rows as shown above in Matlab.

So the logic of fprintf() command to display variables, numbers or characters in Matlab is simple like that.

Leave your comments and questions below!