Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about How to use Print MATLAB. As you all know that the design of an algorithm is not enough until we observe its results too. So, there should be a debugging tool in order to check the performance and accuracy of the designed algorithm. Debugging tool helps us to improve the algorithm’s performance and accuracy too by observing its output again and again. In this tutorial I will tell you about using print command in MATLB for different purposes. So, in this tutorial I am going to use print command as a debugging tool in order to observe the output of the algorithm. You should also have a look at how to use MATLAB ?
I am going to use print command to either print the desired statement on the command window in MATLAB or to display the graphs on a figure and to automatically save it on any destination wherever you want to. I will elaborate this command with the help of the different examples later in this tutorial. if you new to MATLAB then you should read Introduction to MATLAB. So, now let's have a look at How to use Print MATLAB:
How to use Print MATLAB
In the tutorial How to use Print MATLAB, I will tell you about the use of this command in MATLAB while explaining a lot of examples and by displaying their results. The examples include the printing of the statement on the command window in MATLAB as well as to display the graphs and to save its image.
Here, I am going to print some statement (the name of our website) on the command window using this particular command in m.file.
The use of the command fprintf is shown below.
clc % clears the command window
fprintf('www.TheEngineeringProjects.com\n')% prints the desired statement
Editor also displays that command in the figure shown below.
You can observe the result of this statement on the command window in MATLAB.
The result displayed on the command window is shown in the figure below.
So, that was about how to print the statement on the command window.
Now, I am going to print the result of some mathematical operations applied on some variables, on command window using the same command.
I have assigned different values to the two variables a and
I have calculated their sum and displayed on the command window.
The commands written on the editor are shown in the figure below.
The result of the above commands displayed on the command window is shown in the figure below.
So, that was the description of how to print the results mathematical operations applied on some variables on command window.
Now, I am going to perform some operations on matrix.
The source code written in editor of the MATLAB is shown below.
I have initialized a matrix named as
I have then displayed that matrix on the command window.
At the end, I have printed all the values of that matrix on the command window.
The result of all the above commands displayed on the command window is shown in the figure below.
First row in the above figure displays the matrix.
And the second row prints each value of the matrix in next ling using \n.
Graphics Format File
You need to specify file name and format switch to save your figure as graphics.
The supported output formats for exporting from MATLAB and switch settings are shown in the table given below.
Print Paper Copy of Figure
In this method a new bar chart will be created and printed to your system default computer. If you do not specify the figure to be printed, then print will use the current figure.
The source code written on the editor is shown below.
The editor window with the code is also shown in the figure below.
The figure generated from the above code is shown below.
That was the detailed discussion about using print command as a debugging tool in MATLAB.
So, that is all from the tutorial How to use Print MATLAB. I hope you enjoyed this tutorial. If you face any sort of problems regarding anything, you can ask me freely in comments every time, without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. There's another interesting MATLAB Projects named as Eye Ball Detection in MATLAB. I will explore different software including MATLAB in my next tutorials and will share all of them with you guys as well. So, till then, take care :)
I am Syed Zain Nasir, the founder of The Engineering Projects (TEP). I am a
programmer since 2009 before that I just search things, make small projects and now I am sharing my
knowledge through this platform. I also work as a freelancer and did many projects related to
programming and electrical circuitry. My Google Profile+Follow