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

An explanation of Matlab tutorials

Rating
-
Sold
1
Pages
20
Uploaded on
11-12-2017
Written in
2017/2018

The codes written during the matlab tutorial with a step by step explanation of what we are programming.

Institution
Course










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

Written for

Institution
Study
Course

Document information

Uploaded on
December 11, 2017
Number of pages
20
Written in
2017/2018
Type
Manual
Contains
Unknown

Subjects

Content preview

Commands
Arrays and Matrices
Name = begin number:step width:end number
If there is no step width defined than it is automatically one

(begin number ⋯ end number)

Name = [number1, number2, number3; number4, number5, number6]

(number
number 1
4
number 2 number 3
number 5 number 6 )
size(Name)
number of rows , number of columns

Name = linspace( begin number, end number, number of steps)
(begin number ⋯ end number)
For example linspace (0,10,3)
(0 5 10)
If you don’t define a number of steps Matlab automatically assumes you want 100 steps

randn(n, m)
return a matrix n x m matrix of normally distributed random numbers

Saving and loading of documents
save (‘file_name’)
load (‘file_name.mat’)

Clearing Matlab
clear
this command clears the workspace

clc
this command clear the command window

Reading in file
Filename = ‘file.csv’

Name = cvsread(filename)
Read in comma separated file

Name(:,colomn number)
Prints that colomn

Name = num2string(filename)
Convert numerical data into a data string

dataNumber = datenum(date_strings, ‘yyyymmdd’)
Turns a date string into matlab internal date numbers

Dates = datastr(dataNumber, formatOut)
Format matlab internal date numbers into readable date numbers. The Formatout is the format you get the
dates in. If you for example use 24 as formatOut you get the dates in the following manner dd/mm/yyyy.
Instead of 24 you can also write ‘dd/mm/yyyy’ as FormatOut.

,New_vector = Name(:,column)
Write a certain statistic in own vector

 If you want to have a vector with the log returns you have to create a vector with only closing prices.
Then create a new vector by using the following formula
Log_returns = diff(log(closeprices))
Graphs
plot (Name)
plot vector Name in a graph. If the input is a matrix Matlab will plot each column.

plot( Namex, Namey)
Plot vector Namey in a graph and use Namex as the x-coordinates

 If you want to plot the log returns Namex is dateNumber(2:end), because you are taking difference the
first data point gets lost in the process. This will plot the returns against the matlab internal dates. If
you want readable date to be on the x-axis you have to use the following command
datetick (‘x’)

title(‘title_name’)
xlabel(“xlabel_name’)
ylabel(“ylabel_name’)
The commands above will add a title and/or labels fort the x-axis and y-axis

qqplot(name)
Displays a quantile-quantile plot of the quantiles of the sample data versus the theoretical quantiles values from
a normal distribution.

qqplot(name)
Displays a quantile-quantile plot of the quantiles of the sample data versus the theoretical quantiles values from
the distribution specified

Basic data analysis
length(name)
Gives the number of observations

sum(name)
Gives the sum of all the observations

prod(name)
Gives the product of all observations

min(name)
max(name)
Gives the minimum and maximum of all the observations

range(name)
Gives the difference between the minimum and maximum

mean(name)
median(name)
var(name)
std(name)
sqrt(var(name))
skewness(name)
kurtosis(name)

, Gives information about the distribution of the variable name

corrcoef(name)
Returns the matrix of correlation coefficients for name, where the columns of name represent random variables
and the rows represent observations.

quantile(name, probability)
Gives you the value that belongs to that probability. The chance that a value is smaller than the output is equal
to the probability you put in for input

sort(name)
Puts the values of the vector in the order from small to large

abs(name)
Makes all the values of the vector absolute

diff(name)
Takes the differences between the observations

Matrix Calculations
MatrixA= [number 1, number 2; number3, number 4]
MatrixB= [number 5, number 6; number7, number 8]
MatrixA .* MatrixB

(number 1∗number 5
number 3∗number 7
number 2∗number 6
number 4∗number 8 )
MatrixA * MatrixB
Multiplying matrices the same way as always (row times column)

MatrixA’
Gives the transpose of matrix A

Distributions
normalpdf(x, mu, sigma)
the chance you find value x in the normal distribution with mean mu and standard deviation sigma. If you put in
a vector your output will be a vector with probabilities. If mu and sigma are not defined Matlab assume mu to
be zero and sigma to be 1 (Z-distribution).

normalcdf(x, mu, sigma)
the chance you find value x or smaller in the normal distribution with mean mu and standard deviation sigma. If
you put in a vector your output will be a vector with probabilities. If mu and sigma are not defined Matlab
assume mu to be zero and sigma to be 1 (Z-distribution).

norminv(p, mu, sigma)
The output is the value for which the probability you will obtain that exact value or something smaller, is equal
to p.

normrnd(mu, sigma, number of rows, number of columns)
Creates a matrix with every cell containing a random variable of a normal distribution with mean mu and
standard deviation sigma.

[muhat,sigmahat,muci,sigmaci] = normfit(name)
Estimates the mu and sigma for each colomn of data. Also gives the confidence intervals (first a row with the
lower bound and then a row with upper bounds). If muci and sigmaci aren’t put in you only receive the
estimates as output

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.
wandykalk Vrije Universiteit Amsterdam
Follow You need to be logged in order to follow users or courses
Sold
80
Member since
8 year
Number of followers
55
Documents
17
Last sold
1 year ago

3.9

19 reviews

5
3
4
12
3
4
2
0
1
0

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 tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right 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 aced it. It really can be that simple.”

Alisha Student

Frequently asked questions