0% found this document useful (0 votes)
7 views19 pages

Matlab Lesson 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 19

Faculty: engineering and technology

Department: all departments


Cohort3:year 1(first semester)
Module: computation and visualization
Tutor: Mr. doe
Assistance tutor: alimamy sesay
Due date:3/04/2024.
Grading pattern
NAME ID QUIZ 1 QUIZ 2 MID- FINAL
5% 5% SEM.TES 10% SEM.
T EXAM
15% 15%
INTRODUCTION
Individuals employed in mechanical engineering careers attempt
to solve engineering problems using the tools and information
available to them.
 In situations where engineering needs to interpret, modify, or
use data or other mathematical information efficiently the
engineer may turn to a coding language to help them complete a
task.
In addition to running electronic devices around the world,
computer code can be written by an engineer to compute
mathematical operations, create a graphical depiction of data, or
complete work much faster than the engineer would have been
able to do by hand.
INTRODUCTION.cont.
MATLAB originated from “MATRIX LAORATORY”

Initially derived in research papers by J.H. Wilkinson at the


National Physical Laboratory

In 1960s
APPLICATIONS OF MATLAB
Calculating the values for the resultant of a force system.
 Determine value regarding materials such as sheer, strain, or
margins of safety.
 Determine if boats made with different dimensions or materials
would sink or float in various fluids.
 Interpreting, calculating, and displaying data sets.
APPLICATIONS OF MATLAB
Development of applications
with graphical user interfaces.
Create repeatable and
sharable methods for solving
engineering problems.
THE COMMAND WINDOW(SHOWN
IN BLUE COLOR)
 The primary MATLAB user interface.
 The primary home for writing and running codes in
MATLAB programme.
 The home for viewing codes result
 These codes can also be ruined in “script ‘’ files.
 When running a script, a user will see outputs from the
command window and can also add other information
through the command window.
 The picture on the right shows basic mathematical
operations performed in MATLAB.
 The highlighted portions show what the user typed into the
window, while the remainder is the output by MATLAB.
MATLAB LAYOUT AND INTERFACE
The Command Window. CONT.
You can clear the command window
displayed by typing “clc”, on the
command window and press enter
Alternatively, you can click on the
“clear command” on the toolbar.
For example, completing an arithmetic
operation in MATLAB such as 238*5
will result in the window to the right.
Typing clc and pressing enter will clear
the text in the window.
The Command Window. CONT.
When writing scripts, you will want to
start with a blank command window
and reset any operations that the code
may have carried out.
 This can be accomplished by writing
two lines of code at the beginning of
the script with “clc” and the “close all”
command.
 This is demonstrated in the example
script below. As a result of these two
lines, the text in the command window
will reset each time the code is run.
PROGRAMME AND CURRENT
FOLDER
Script program files can be saved
and referenced later or transferred
to other computers, unlike code
written directly through the
command window.
 Within MATLAB, it will be
essential to save all scripts to the
same folder, which is referred to
as the current folder in MATLAB.

PROGRAMME AND CURRENT
FOLDER.cont.
The current folder is shown directly below the toolbar and is
highlighted in yellow in the above window.

The highlighted portions show what the user typed into the
window, while the remainder is the output by MATLAB.
PROGRAMME AND CURRENT
FOLDER.CONT.
By saving your scripts to the same folder you
will be able to keep everything in the same place
and reference different files without changing
folders.
Script files, which are saved in .m format, are
listed within the red programs section of the
MATLAB user interface image above.
 When a .m file is selected, information about
the file will be displayed in the details window,
which is depicted in orange in the above image.
PROGRAMME AND CURRENT FOLDER.CONT.
Note the following when saving files in MATLAB:
i)the file name should bare the same name as the program and if
possible the date the file was created within the file name.
ii)it is important to note that file names cannot include spaces,
hyphens, dashes, or numbers as their first digit.
iii)To make file names readable, I recommend using underscores
and capital letters to make quality file names (i.e.
“QuadraticEquation9_23_2019” is much more
informative than “untitled5”).
THE EDITOR WINDOW
The editor window is the home of
MATLAB script files
Codes are run step-by-step when
written in the command window.
In the case of scripts within the
editor ,codes are written by the
user and only ran when
commanded by the user by
selecting the run button in the
editor window of MATLAB.
THE EDITOR WINDOW.CONT.
The editor window also is
home to expanded views of
variables.
When a variable from within
the variables window is selected
by double-clicking, a window
will overlay the editor and any
open scripts to show the
contents of the variable.
THE WORKSPACE
When writing scripts in MATLAB many variables
will be introduced to represent data or to be used in
formulae.
To assist the user in determining which variables
have been assigned in a script, the workspace will
show each variable and the values that are assigned
to them.
This will be helpful when writing long codes using
many similar variables and will help keep track of
variable meanings.
THE WORKSPACE.CONT.
Various forms of variables that exist
within the MATLAB coding language
are displayed within the Workspace.
This includes numbers, characters,
words, and more complicated double
objects with arrays and matrices, and
histograms.
An example of a workspace for a code
with several variable types is included
below.
Notice how each variable is assigned its
own name by the user, allowing for it to
be identified within the code.
SUMMARY
MATLAB is an essential tool for all Engineers.
MATLAB means Matrix Laboratory.
MATLAB interface is divided into 4 main parts.
Command window is the primary home for running codes in
MATLAB.
Clc is the shortcut key for restarting the command window.
Edit is the shortcut key for opening new script file.
The file name must bare the same name as the programme
name.
Current folder is the home for all saved script files.

You might also like