SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
MATLAB Cheat Sheet
Basic Commands
% Indicates rest of line is commented out.
; If used at end of command it suppresses output.
If used within matrix definitions it indicates the end of a row.
save filename Saves all variables currently in workspace to file filename.mat.
save filename x y z Saves x, y, and z to file filename.mat.
save -append filename x Appends file filename.mat by adding x.
load filename Loads variables from file filename.mat to workspace.
! Indicates that following command is meant for the operating system.
... Indicates that command continues on next line.
help function/command Displays information about the function/command.
clear Deletes all variables from current workspace.
clear all Basically same as clear.
clear x y Deletes x and y from current workspace.
home Moves cursor to top of command window.
clc Homes cursor and clears command window.
close Closes current figure window.
close all Closes all open figure windows.
close(H) Closes figure with handle H.
global x y Defines x and y as having global scope.
keyboard When placed in an M-file, stops execution of the file and gives
control to the user’s keyboard. Type return to return control
to the M-file or dbquit to terminate program.
A=xlsread(‘data’,... Sets A to be a 5-by-2 matrix of the data contained in
‘sheet1’,‘a3:b7’) cells A3 through B7 of sheet sheet1 of excel file data.xls
Succes=xlswrite(... Writes contents of A to sheet sheet1 of excel file
‘results’,A,‘sheet1’,‘c7’) results.xls starting at cell C7. If successful success= 1.
path Display the current search path for .m files
addpath c:my_functions Adds directory c:my_functions to top of current search path.
rmpath c:my_functions Removes directory c:my_functions from current search path.
disp(’random statement’) Prints random statement in the command window.
disp(x) Prints only the value of x on command window.
disp([’x=’,num2str(x,5)]) Displays x= and first 5 digits of x on command window. Only works
when x is scalar or row vector.
fprintf(...
Displays The 3 is 1.73. on command window.
’The %g is %4.2f.n’, x,sqrt(x))
format short Displays numeric values in floating point format with 4 digits after
the decimal point.
format long Displays numeric values in floating point format with 15 digits after
the decimal point.
Plotting Commands
figure(H) Makes H the current figure. If H does not exist is creates H.
Note that H must be a positive integer.
plot(x,y) Cartesian plot of x versus y.
plot(y) Plots columns of y versus their index.
plot(x,y,‘s’) Plots x versus y according to rules outlined by s.
semilogx(x,y) Plots log(x) versus y.
semilogy(x,y) Plots x versus log(y).
loglog(x,y) Plots log(x) versus log(y).
grid Adds grid to current figure.
title(‘text’) Adds title text to current figure.
xlabel(‘text’) Adds x-axis label text to current figure.
ylabel(‘text’) Adds y-axis label text to current figure.
hold on Holds current figure as is so subsequent plotting commands add
to existing graph.
hold off Restores hold to default where plots are overwritten by new plots.
Creating Matrices/Special Matrices
A=[1 2;3 4] Defines A as a 2-by-2 matrix where the first row contains the
numbers 1, 2 and the second row contains the number 3, 4.
B=[1:1:10] Defines B as a vector of length 10 that contains the numbers
1 through 10.
A=zeros(n) Defines A as an n-by-n matrix of zeros.
A=zeros(m,n) Defines A as an m-by-n matrix of zeros.
A=ones(n) Defines A as an n-by-n matrix of ones.
A=ones(n,m) Defines A as an m-by-n matrix of ones.
A=eye(n) Defines A as an n-by-n identity matrix.
A=repmat(x,m,n) Defines A as an m-by-n matrix in which each element is x.
linspace(x1, x2, n) Generates n points between x1 and x2.
Matrix Operations
A*B Matrix multiplication. Number of columns of A must equal number
of rows of B.
Aˆn A must be a square matrix. If n is an integer and n > 1 than Aˆn is
A multiplied with itself n times. Otherwise, Aˆn is the solution to
An
vi = livi where li is an eigenvalue of A and vi is the corresponding
eigenvector.
A/B This is equivalent to A*inv(B) but computed more efficiently.
AB This is equivalent to inv(A)*B but computed more efficiently.
A.*B,A./B,
Element-by-element operations.
A.B,A.ˆn
A’ Returns the transpose of A.
inv(A) Returns the inverse of A.
length(A) Returns the larger of the number of rows and columns of A.
size(A) Returns of vector that contains the dimensions of A.
size(A,1) Returns the number of rows in A.
reshape(A,m,n) Reshapes A into an m-by-n matrix.
kron(A,B) Computes the Kronecker tensor product of A with B.
A = [A X] Concatenates the m-by-n matrix A by adding the m-by-k matrix X as
additional columns.
A = [A; Y] Concatenates the m-by-n matrix A by adding the k-by-n vector Y as
additional rows.
Data Analysis Commands
rand(m,n) Generates an m-by-n matrix of uniformly distributed random numbers.
randn(m,n) Generates an m-by-n matrix of normally distributed random numbers.
max(x) If x is a vector it returns the largest element of x.
If x is a matrix it returns a row vector of the largest element in each
column of x.
min(x) Same as max but returns the smallest element of x.
mean(x) If x is a vector it returns the mean of the elements of x.
If x is a matrix it returns a row vector of the means for each column of x.
sum(x) If x is a vector it returns the sum of the elements of x.
If x is a matrix it returns a row vector of the sums for each column of x.
prod(x) Same as sum but returns the product of the elements of x.
std(x) If x is a vector it returns the standard deviation of the elements of x.
If x is a matrix it returns a row vector of the standard deviations for each
column of x.
var(x) Same as std but returns the variance of the elements of x.
Conditionals and Loops
for i=1:10
procedure Iterates over procedure incrementing i from 1 to 10 by 1.
end
while(criteria)
procedure Iterates over procedure as long as criteria is true.
end
if(criteria 1)
If criteria 1 is true do procedure
1, else if criteria 2 is true do
procedure 2, else do procedure 3.
procedure 1
elseif(criteria 2)
procedure 2
else
procedure 3
end

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Mbd2
Mbd2Mbd2
Mbd2
 
Commands list
Commands listCommands list
Commands list
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Lec5
Lec5Lec5
Lec5
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
Lec2
Lec2Lec2
Lec2
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methods
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
mat lab introduction and basics to learn
mat lab introduction and basics to learnmat lab introduction and basics to learn
mat lab introduction and basics to learn
 

Ähnlich wie Matlab cheatsheet

Ähnlich wie Matlab cheatsheet (20)

Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
 
ML-CheatSheet (1).pdf
ML-CheatSheet (1).pdfML-CheatSheet (1).pdf
ML-CheatSheet (1).pdf
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAY
 
Matlab
MatlabMatlab
Matlab
 
R Programming Reference Card
R Programming Reference CardR Programming Reference Card
R Programming Reference Card
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
 
@ R reference
@ R reference@ R reference
@ R reference
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdfMATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
 
LMD UGR
LMD UGRLMD UGR
LMD UGR
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
 
Reference card for R
Reference card for RReference card for R
Reference card for R
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Matlab cheatsheet

  • 1. MATLAB Cheat Sheet Basic Commands % Indicates rest of line is commented out. ; If used at end of command it suppresses output. If used within matrix definitions it indicates the end of a row. save filename Saves all variables currently in workspace to file filename.mat. save filename x y z Saves x, y, and z to file filename.mat. save -append filename x Appends file filename.mat by adding x. load filename Loads variables from file filename.mat to workspace. ! Indicates that following command is meant for the operating system. ... Indicates that command continues on next line. help function/command Displays information about the function/command. clear Deletes all variables from current workspace. clear all Basically same as clear. clear x y Deletes x and y from current workspace. home Moves cursor to top of command window. clc Homes cursor and clears command window. close Closes current figure window. close all Closes all open figure windows. close(H) Closes figure with handle H. global x y Defines x and y as having global scope. keyboard When placed in an M-file, stops execution of the file and gives control to the user’s keyboard. Type return to return control to the M-file or dbquit to terminate program. A=xlsread(‘data’,... Sets A to be a 5-by-2 matrix of the data contained in ‘sheet1’,‘a3:b7’) cells A3 through B7 of sheet sheet1 of excel file data.xls Succes=xlswrite(... Writes contents of A to sheet sheet1 of excel file ‘results’,A,‘sheet1’,‘c7’) results.xls starting at cell C7. If successful success= 1. path Display the current search path for .m files addpath c:my_functions Adds directory c:my_functions to top of current search path. rmpath c:my_functions Removes directory c:my_functions from current search path. disp(’random statement’) Prints random statement in the command window. disp(x) Prints only the value of x on command window. disp([’x=’,num2str(x,5)]) Displays x= and first 5 digits of x on command window. Only works when x is scalar or row vector. fprintf(... Displays The 3 is 1.73. on command window. ’The %g is %4.2f.n’, x,sqrt(x)) format short Displays numeric values in floating point format with 4 digits after the decimal point. format long Displays numeric values in floating point format with 15 digits after the decimal point. Plotting Commands figure(H) Makes H the current figure. If H does not exist is creates H.
  • 2. Note that H must be a positive integer. plot(x,y) Cartesian plot of x versus y. plot(y) Plots columns of y versus their index. plot(x,y,‘s’) Plots x versus y according to rules outlined by s. semilogx(x,y) Plots log(x) versus y. semilogy(x,y) Plots x versus log(y). loglog(x,y) Plots log(x) versus log(y). grid Adds grid to current figure. title(‘text’) Adds title text to current figure. xlabel(‘text’) Adds x-axis label text to current figure. ylabel(‘text’) Adds y-axis label text to current figure. hold on Holds current figure as is so subsequent plotting commands add to existing graph. hold off Restores hold to default where plots are overwritten by new plots. Creating Matrices/Special Matrices A=[1 2;3 4] Defines A as a 2-by-2 matrix where the first row contains the numbers 1, 2 and the second row contains the number 3, 4. B=[1:1:10] Defines B as a vector of length 10 that contains the numbers 1 through 10. A=zeros(n) Defines A as an n-by-n matrix of zeros. A=zeros(m,n) Defines A as an m-by-n matrix of zeros. A=ones(n) Defines A as an n-by-n matrix of ones. A=ones(n,m) Defines A as an m-by-n matrix of ones. A=eye(n) Defines A as an n-by-n identity matrix. A=repmat(x,m,n) Defines A as an m-by-n matrix in which each element is x. linspace(x1, x2, n) Generates n points between x1 and x2. Matrix Operations A*B Matrix multiplication. Number of columns of A must equal number of rows of B. Aˆn A must be a square matrix. If n is an integer and n > 1 than Aˆn is A multiplied with itself n times. Otherwise, Aˆn is the solution to An vi = livi where li is an eigenvalue of A and vi is the corresponding eigenvector. A/B This is equivalent to A*inv(B) but computed more efficiently. AB This is equivalent to inv(A)*B but computed more efficiently. A.*B,A./B, Element-by-element operations. A.B,A.ˆn A’ Returns the transpose of A. inv(A) Returns the inverse of A. length(A) Returns the larger of the number of rows and columns of A. size(A) Returns of vector that contains the dimensions of A. size(A,1) Returns the number of rows in A. reshape(A,m,n) Reshapes A into an m-by-n matrix.
  • 3. kron(A,B) Computes the Kronecker tensor product of A with B. A = [A X] Concatenates the m-by-n matrix A by adding the m-by-k matrix X as additional columns. A = [A; Y] Concatenates the m-by-n matrix A by adding the k-by-n vector Y as additional rows. Data Analysis Commands rand(m,n) Generates an m-by-n matrix of uniformly distributed random numbers. randn(m,n) Generates an m-by-n matrix of normally distributed random numbers. max(x) If x is a vector it returns the largest element of x. If x is a matrix it returns a row vector of the largest element in each column of x. min(x) Same as max but returns the smallest element of x. mean(x) If x is a vector it returns the mean of the elements of x. If x is a matrix it returns a row vector of the means for each column of x. sum(x) If x is a vector it returns the sum of the elements of x. If x is a matrix it returns a row vector of the sums for each column of x. prod(x) Same as sum but returns the product of the elements of x. std(x) If x is a vector it returns the standard deviation of the elements of x. If x is a matrix it returns a row vector of the standard deviations for each column of x. var(x) Same as std but returns the variance of the elements of x. Conditionals and Loops for i=1:10 procedure Iterates over procedure incrementing i from 1 to 10 by 1. end while(criteria) procedure Iterates over procedure as long as criteria is true. end if(criteria 1) If criteria 1 is true do procedure 1, else if criteria 2 is true do procedure 2, else do procedure 3. procedure 1 elseif(criteria 2) procedure 2 else procedure 3 end