100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Functions Matlab

Rating
-
Sold
-
Pages
30
Uploaded on
13-01-2025
Written in
2024/2025

This document includes all the functions used in the course of Matlab

Institution
Module










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Module

Document information

Uploaded on
January 13, 2025
Number of pages
30
Written in
2024/2025
Type
Summary

Subjects

Content preview

FUNCTIONS AND CODES MATLAB

INTRODUCTION TO MATLAB
Getting information
help elfun Help, followed by the function you
want to search for, to get some
more information about that
specific function.
whos Shows the variables that are in the
workplace, suppling their name,
size, bytes, class and attributes
size(A) Give dimensions (i.e. number of
rows and columns) of your matrix
A.
find The find function converts a logical
F = find(D) index into a subscript index by
returning the positions of all
nonzero (or true) elements in the
logical array.

Basic Syntax
x = pi Create variables and assign values with the equal sign (=).
The left side (x) is the variable name, and the right side (pi)
is its value.
Matrices are denoted by upper case letters whereas vector
and scalars are denoted by lower case letters.
y = sin (- Provide inputs to a function using parentheses.
5)

Desktop Management
save save data.mat Save your current workspace
to a MAT-file
load load data.mat Load the variables in a MAT-
file to the workspace.
clear clear Clear all variables from the
clear A workspace.
Clear variable A.
clc clc Clear all text from the
Command Window.
format format long Change how numeric output
format short appears in the Command
Window.
close all close all Close all figures
which which(‘Tutorial_part6_withans From where matlab is running
wers’) a certain command
dlmwrit dlmwrite(‘my.data.txt’, data, ‘\ Save stuff in ASCII text format
e t’) to load into SPSS or Excel

,Array Types
4 Scalar
[3 5 8 10] Row vector; row of numbers (one-
dimensional array)
[1;3;5;6] Colum vector; column of numbers
(one-dimensional array). A
semicolon between the squared
brackets basically means: "start a
new row".
[3 4 5; 6 7 8] Matrix; a rectangular array of
numbers (two-dimensional array).
Commas or spaces to separate the
columns within a row and use
semicolons to start new rows.
M_addition = [1, 15, 18] Create an extra row.
M_new = [M; M_addition] Add extra row to original matrix M.

new_row = [30 31 32 33 34] A = magic (5)
A = [A; new_row] A(6,:) = new_row
g = [a(:,1),b(:,4)] g is column 1 of a next to column 4
of b

Evenly Spaced Vectors
1:4 Create a vector from 1 to 4, spaced by 1, using
the colon operator (:).
1:0.5:4 Create a vector from 1 to 4, spaced by 0.5.
linspace(1,10,5) Create a vector with 5 elements. The values are
evenly spaced from 1 to 10.

Matrix and Vector Creation
rand(2) Create a square matrix with 2 rows and 2 columns.
zeros(2,3) Create a rectangular matrix with 2 rows and 3 columns of
0s.
ones(2,3) Create a rectangular matrix with 2 rows and 3 columns of
1s.

zeros() Creates an array of zeros.
ones() Creates an array of ones.
randn() Generates random numbers with a normal distribution (mean
0 and standard deviation 1), where numbers can be either
positive or negative
rand() rand(3,5)
Create a matrix of uniformly distributed random numbers
between 0 and 1 with 3 rows and 5 columns
repmat() Replicates and tiles an array to create a larger array.

B = repmat(A, m, n)
Replicates matrix A m times in the row dimension and n times
in the column dimension

, linspace Generates linearly spaced vectors. It creates an array of
() evenly spaced numbers between two specified values

L = linspace(a, b, n)
Generates n points between a and b
logspace Generates logarithmically spaced vectors. It creates an array
() of numbers spaced evenly on a log scale between two
specified powers of 10.

L = logspace(p1, p2, n)
Generates n points between 10^p1 and 10^p2

Array Indexing
A(end,2) Access the element in the second column of the last
row.
A(2,:) Access the entire second row.
A(1:3,:) Access all colums of the first three rows.
A(2) = 11 Change the value of the second element of an array to
11.
A(:,4)=0 Change all values in column 5 to zero.

Array Operations
[1 2; 3 4] + 1 Perform array addition.
ans =
2 3
4 5
[1 1; 1 1]*[2 2; 2 2] Perform matrix multiplication.
ans =
4 4
4 4 Each row of the first matrix is multiplied
by each column of the second matrix
according to the rules of linear algebra.
[1 1; 1 1].*[2 2; 2 2] Perform element-wise multiplication.
ans =
2 2
2 2

Operators
.* Means element-wise multiplication




To perform an element-wise operation, the arrays involved
must be the same size, or one must be scalar (a single value
that applies to all elements of the other array).
./ Means element-wise division
.^ Means element-wise power
* Means matrix multiplication

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
fleurheling Universiteit Utrecht
Follow You need to be logged in order to follow users or courses
Sold
54
Member since
4 year
Number of followers
22
Documents
123
Last sold
1 week ago

2.8

4 reviews

5
0
4
2
3
0
2
1
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions