Another way to print to MATLAB's Command Window is by using the 'fprintf()' function. Unlike the 'disp()' function, 'fprintf()' can allow for more formatting. The way 'fprintf()' works is a string is written, but identifiers are added to point where different variable's values should go. Let's take a look at the identifiers we can use.
There are certainly a lot of different features, and there are more, but we will take things one step at a time. They will become fluent the more they are used! Let's take a look at a use.
matlab
age = 18;
name = "Steve";
fprintf("Today, %s is %i", name, age); % output: "Today, Steve is 18"
We can do even more formatting with the 'fprintf()' function by rounding numbers. Let's take a look.
matlab
age = 18.9324;
name = "Steve";
fprintf("Today, %s turned %5.2d", name, age);
% output: "Today, Steve turned 1.89e+01"
Now we can print our data to the Command Window; this will make verification and communicating with the user much easier!