moayed almobaied dissertation supervisors: prof. dr...
TRANSCRIPT
![Page 1: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/1.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
OUTPUT COMMANDS
Two commands that are frequently used to generate output are:
disp and fprintf
The disp command displays the output on the screen, while the
fprintf command can be used to display the output on the screen
or to save the output to a file.
The commands can be used in the Command Window, in a
script file, and in a function file.
![Page 2: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/2.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
The disp Command
The disp command is used to display the elements of a variable
without displaying the name of the variable, and to display text.
The format of the disp command is:
![Page 3: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/3.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 4: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/4.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
Only one variable can be displayed in a disp command.
If elements of two variables need to be displayed together, a new
variable (that contains the elements to be displayed) must first be
defined and then displayed.
![Page 5: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/5.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
In many situations it is nice to display output (numbers) in a table.
This can be done by first defining a variable that is an array with the
numbers and then using the disp command to display the array.
Since in the disp command the user cannot control the format (the
width of the columns and the distance between the columns)
of the display of the array, the position of the headings has to be
aligned with the columns by adding spaces.
![Page 6: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/6.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 7: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/7.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
The fprintf Command
The fprintf command can be used to display output (text and data)
on the screen or to save it to a file. With this command (unlike with
the disp command) the output can be formatted.
For example, text and numerical values of variables can be
intermixed and displayed in the same line.
In addition, the format of the numbers can be controlled.
![Page 8: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/8.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
With many available options, the fprintf command can be long and
complicated.
To avoid confusion, the command is presented gradually.
How to use the command to display text messages.
How to mix numerical data and text.
How to format the display of numbers.
How to save the output to a file.
![Page 9: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/9.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
Using the fprintf command to display text:
Example:
![Page 10: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/10.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 11: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/11.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 12: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/12.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
Using the fprintf command to display a mix of text and numerical
data:
![Page 13: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/13.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 14: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/14.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 15: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/15.jpg)
Computer Programming Lecture 11
![Page 16: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/16.jpg)
Computer Programming Lecture 11
![Page 17: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/17.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
![Page 18: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/18.jpg)
Computer Programming Lecture 11
![Page 19: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/19.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
Additional remarks about the fprintf command:
To place a single quotation mark in the displayed text, type two
single quotation marks in the string inside the command.
The fprintf command is vectorized. This means that when a
variable that is a vector or a matrix is included in the command,
the command repeats itself until all the elements are displayed.
If the variable is a matrix, the data is used column by column.
![Page 20: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/20.jpg)
Computer Programming Lecture 11
![Page 21: Moayed Almobaied Dissertation Supervisors: Prof. Dr ...site.iugaza.edu.ps/ahdrouss/files/2018/10/Presentation9a.pdfIslamic University of Gaza Faculty of Engineering Civil Engineering](https://reader033.vdocuments.us/reader033/viewer/2022060821/609a55c17047f029dd77b104/html5/thumbnails/21.jpg)
Islamic University of GazaFaculty of EngineeringCivil Engineering Department
Computer Programming Lecture 11
Using the fprintf command to save output to a file:
4.4 THE save AND load COMMANDS
4.5 IMPORTING AND EXPORTING DATA
Later( after Ch6)