MATLAB
&
Computer Programming
Fundamentals
Computer Programming
COMP 361
Presented By: Eng. Bushra
Melhem 1
Outline
o Introduction to MATLAB
o MATLAB Applications
o Computer Programming Fundamentals
Computer internal organization
Computer software
Computer Programming
Programming Languages
Programming Process
o Summary
What is MATLAB
o MATLAB (short for MATrix LABoratory) is a
special-purpose computer program, optimized to
perform engineering and scientific calculations.
o The MATLAB program implements the MATLAB
programming language and provides a very
extensive library of predefined functions to make
technical programming tasks easier and more
efficient. MATLAB is a huge program with an
incredibly rich variety of functions.
Contd
o Even the basic version of MATLAB without any toolkits is much richer
than other technical programming languages. There are more than
1000 functions in the basic MATLAB product alone.
o The toolkits extend this capability with many more functions in various
specialties such as:
Simulink
Symbolic Math Toolbox
Control System Toolbox
Signal Processing Toolbox
DSP System Toolbox
Statistics Toolbox
Optimization Toolbox
Image Processing Toolbox
MATLAB Applications in
Academics
MATLAB will be a beneficial tool in problem
solving through out your degree program. It
will be used in courses such as:
Circuits & Electronics
Signals & Systems
Control System
BioMedical Image Processing
Digital Signal Processing
MATLAB Application in Industry
o The ability to use tools such as MATLAB is
quickly becoming a requirement for many
engineering positions.
o Widely used in all engineering and science
fields, MATLAB is particularly popular for
Biomedical and Electrical Engineering
applications.
MATLAB Application in the Industry-
Biomedical Engineering
o Medical images are
usually saved as dicom
files (the Digital Imaging
and Communications in
Medicine standard).
o Dicom files use the file
extension .dcm
o Image Processing Toolbox
can read these files,
making their data available
to MATLAB.
Computer Programming Fundamentals
As MATLAB is introduced in detail. Lets link it
to programming fundamentals. For that we
will start with the:
Computer internal organization
Computer software
Computer programming
Programming languages
Programming process
Computer Programming Fundamentals
Computer internal organization
Computer software
Computer Programming
Programming Languages
Programming Process
Computer Internal Organization
Computer Programming Fundamentals
Computer internal organization
Computer software
Computer Programming
Programming Languages
Programming Process
Computer Software
o System software- operating system, controls the
interaction between machine and user.
Communicate with computer user.
Manage memory, hard drive, and peripherals.
Collect input/Display output.
Read/Write data.
Examples: Windows, Dos, Unix, Linux,… etc.
o Application Software - developed to assist a
computer user in accomplishing specific tasks.
Examples: Word, Excel, Internet Explorer, programming
languages,…...etc.
Computer Programming Fundamental
Computer internal organization
Computer software
Computer Programming
Programming Languages
Programming Process
Computer Programming
o We cannot program a computer using Natural
languages such as Arabic or English – too
ambiguous
o A Computer Programming Language provides
a precise way of specifying a set of
instructions to a computer.
Programming Related Terms
o Program – a set of detailed, step-by-step
instructions that directs the computer to do
what you want it to do.
o To write a program, a computer programmer
uses a programming language.
o Programming language – a set of written
words, symbols, and codes with a strict set of
rules called the language syntax.
Programming – A Skill
o Programming is a skill that must be developed
o Driving a car cannot be learned by reading a
book only, you must practice
o Learning a language cannot be learned by
reading a book, you must practice
o Programming is also a skill and cannot be
learned by reading a book only, YOU MUST
PRACTICE
o Attend class and lab sessions regularly and do
assignments.
Why Learn Programming?
o Programming teaches you how to solve
problems.
o Programming helps you to be more precise.
o You may not be programming expert, but
knowing a little bit about Computer Science and knowing a little
bit about Programming will help you work with people who do
and enhance your interdisciplinary skills.
Computer Programming Fundamentals
o Computer internal organization
o Computer software
o Computer Programming
o Programming Languages
o Programming Process
Programming Languages
o Machine language
− Programs and memory locations are written in
strings of 0’s and 1’s
− It was the only option available to early
programmers.
o Assembly Language
− Substitute mnemonic codes for 0’s and 1’s
− For example, Add for addition, Comp for
compare… etc.
− Use names rather than binary addresses for
memory locations.
Programming Languages-Contd
High Level Languages
Combine algebraic expressions and symbols from English
Requires a compiler to convert the statements into machine language
High level languages includes the following:
FORTRAN
COBOL
MATLAB
BASIC
VISUAL BASIC
C
JAVA
Programming Languages-Contd
o FORTRAN- FORmula TRANslator
Used primarily for engineering, mathematical, and
scientific tasks
o COBOL- Common Business-Oriented Language
Used primarily for business requirements.
Processes large data files.
Produces well-formatted reports
o MATLAB- MATrix LABoratory
o BASIC- Beginners All-Purpose Symbolic Instruction
Code
Developed to teach programming to college students
Programming Languages-Contd
o Visual Basic
Allows programmer to create Windows-like user interfaces
o C
Originally designed to write systems software
Offers the ease of use of a high-level language with the efficiency
of an assembly language
Very portable – can be used with virtually every combination of
computer and operating system (any platform)
o Java
A network-friendly programming language
Very useful for Internet development
Java applets can run in the user’s Web browser
Categories of High Level Languages
1. Procedural Language
In which the programmer describes the step-by-step solution to the
problem. The program specifies the exact sequence of all operations.
Examples: BASIC, C, COBOL, FORTRAN, MATLAB, and Pascal.
2. Object-Oriented Languages (OOP)
Very high-level languages, also called fourth-generation
languages (4GLs), are nonprocedural languages in which the
programmer specifies the desired results and the language develops
the solution.
Programs are no longer procedural, they do not follow a sequential
logic.
The programmer do not take control and determine the sequence of
execution. Instead the user action can cause an event to occur.
Examples: Visual Basic, C#, C++, and Java.
Computer Programming Fundamentals
Computer internal organization
Computer software
Computer Programming
Programming Languages
Programming Process
The Programming Process
The programming process has five main
steps:
1. Defining the problem
2. Planning the solution
3. Coding the program
4. Testing the program
5. Documenting the program
1. Define the Problem
Develop a written agreement that specifies:
The input data
The desired output
The processing required
2. Planning Tools
o Flowchart
A pictorial representation of the algorithm.
Flowcharts are recognized as one of the most
important ways to effectively communicate
ideas between people who may differ in
knowledge, education, and position.
o Program Flowchart
Indicates the operations to be performed and
the sequence in which they occur to solve a
given problem.
o Pseudocode
English-like language
Specifies algorithm with more precision than
you can in English, but less than a
programming language.
Common Flowchart Symbols
Flowline: Flowlines connect the flowchart symbols and
show the sequence of operations during the program
execution.
Terminator: Shows the starting and ending points of
the program. A terminator has flowlines in only one
direction, either in (a stop node) or out (a start node).
Data Input or Output: Allows the user to input data
and results to be displayed.
Processing: Indicates an operation performed by
the computer, such as a variable assignment or
mathematical operation.
Common Flowchart Symbols- Contd
Decision: The diamond indicates a decision
structure. A diamond always has two flowlines out.
One flowline out is labeled the “yes” branch and the
other is labeled the “no” branch.
Predefined Process: One statement denotes a group of
previously defined statements.
Connector: Connectors avoid crossing flowlines, making
the flowchart easier to read. Connectors come in pairs,
one with a flowline in and the other with a flowline out.
Common Flowchart Symbols- Contd
o The usual direction of the flow is from left to right
or top to bottom.
o Only one flow line should come out from a
process symbol.
or
o Only one flow line should enter a decision
symbol, but two or three flow lines, should leave
the decision symbol
Common Flowchart Symbols- Contd
o Only one flow line is used in conjunction with
terminal symbol.
o Avoid the intersection of flow lines (use
connectors).
o Flowchart has to have a logical start and
finish
Flowchart Example
• Where START
− X: working hours
− Y: Pay Rate in Riyals / hour
Read X, Y
Gross Pay = X * Y
Write
Correct the symbols Gross Pay
of this flowchart
END
Flowchart Example
Flowchart for a
Cash Register
3. Coding the Program
o Translating the algorithm from the planning
stage into a formal programming language.
o Programs can be keyed into the computer by
using a text editor.
o The Integrated Development Environment
(IDE) – a package that combines simple
Editor with a compiler, linker, loader, and
often other development tools
o For example: Visual Studio, …Matlab
4. Testing the Program
o Testing requires verifying that the program
actually works as desired, i.e. no errors.
o All languages have syntax rules
Similar to grammatical rules
The computer will reject a program with even
a minor syntax error
Testing the Program - continued
Two phases of testing the program
1. Translation:
• Converting the program into the binary instructions
the CPU understands.
• detects programming language errors, which are
called syntax errors.
• A common translator is a compiler, which translates
the entire program at one time and gives error
messages called diagnostics.
2. Debugging
• Identifying and correcting logic errors in the program.
Block Diagram (Program Testing)
Program Testing-Important Terms
o Compilation: is the process of translating the
source code (high-level) into executable code
(machine level).
o Source file: A file containing the program code
(high-level)
o Object file: a file containing machine language
instructions.
o Executable file: Final code that can be
executed by the computer.
5. Documenting the Program
o Materials are generated at each part of the
development cycle.
o Common examples of documentation
Flowchart and/or pseudo code
Comments within the source code
Testing procedures
Layouts of input and output records
program listing.
Summary
In this lecture we got introduced to MATLAB
and its academic and industrial applications.
Later the computer programming
fundamentals were discussed in detail
starting from computer architecture then
covering computer software, computer
programming, different programming
languages and finally the programming
process was.