Introduction To Matlab For Civil Engineers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

INTRODUCTION TO MATLAB FOR

CIVIL ENGINEERS

L. Kanock
Graduate Civil Engineer
+265 295 519
lkanock@gmail.com
Introduction

MATLAB (Matrix MATLAB It has powerful


Laboratory) is a integrates built in routines
powerful software computation, that enable a
tool widely used in visualization and variety of
engineering programming computations.
environment.
MATLAB Interaction Environment

1. The Command Window

▪ Where you interact with


MATLAB
MATLAB Interaction Environment

2. Workspace

▪ Where your variables are


stored
MATLAB Interaction Environment

3. Current Folder

▪ Where your MATLAB active


working files are stored

▪ MATLAB only runs files in


your current folder
Using MATLAB as a Calculator

▪ Type any Expression you want to evaluate.

▪ If You do not specify an output variable, MATLAB uses


a default variable ans to store the result

▪ Note that the variable ans is created and may be


overwritten if it already exists

▪ To avoid this, declare your own variables.


Create Variables
▪ You can assign variables by typing this variable to this
command line

▪ It is displayed in the command window.

▪ You can proceed to do the following:


Matrices and Arrays
▪ You can create an array (1xn) Matrix by using square brackets
separating elements with space or a comma.

▪ Create a matrix with multiple rows by separating the rows with


semi colon.
Matrices and Arrays Operations
▪ You can create Matrices with special functions like zeros,
rand, and magic.
Matrices and Arrays Operations
▪ Process all the values in Matrix using a single arithmetic
operator or function
Matrices and Arrays Operations
▪ Perform standard Matrix operations:
Matrices and Arrays Operations
▪ To perform element wise operations use the dot as follows
Matrices and Arrays Operations
▪ Combine Matrices using the following functions:
Array Indexing
▪ Consider the following Matrix: ▪ Locate the elements using
the following methods

▪ Or
Array Indexing
▪ Try indexing outside the size ▪ You can Manipulate values
of the Matrix: in Matrix

▪ What error does it bring?


The colon operator
▪ The colon operator allows you to create equally spaced
vector.
▪ It uses the format:
start: step: end

▪ You can also use the colon operator for array indexing
Working with Strings
▪ Strings are enclosed in
double quotes.

▪ Strings in MATLAB are also


in Matrix form.

▪ Type whos to see their


nature.
Working with Inbuilt functions

▪ MATLAB has in built functions that you can


work with
▪ There are numerous of these
▪ Refer to documentation given
Making 2D Plots
Making 2D Plots
▪ You can add plots to an
existing figure.
Making 2D Plots
Making Subplots
▪ You can have multiple
graphs in one plot
▪ You can use the subplot
function to do this
END

You might also like