
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to matlab, a numerical computing environment and programming language used heavily in industry. It covers the similarities and differences between matlab and python, syntax for comments, control structures, functions, scripts, and hands-on exercises. Students will learn how to write and run matlab code, use built-in functions, and debug their programs.
Typology: Study notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























Numerical Computing Environment & ^
Programming Language ^
Made by The MathWorks Inc.
mat
rix
lab
oratory“
^
MATLAB defaults to use a 2D matrix of numbers (oftype double) for as many things as possible ^
Many built in functions without loading libraries ^
Arrays are 1 based not 0 based ^
MATLAB actually has good help docs
☺
^
MATLAB is pricey! Ballpark $5000 the day you stopgoing to Rose to have a personal copy of MATLAB. ^
Used heavily in industry. Very common.
The first program we looked at in C was a print roottable function. Let’s see the syntax in Matlab.^
Review see code in C and Python first See how MATLAB would code the root table problem
will comment a line in MATLAB
^
Similar to # in Python^
Similar to // in C ^
First comment in a file is used as the help message.
x= elseif(a>0)
x= else
x= end elif is done as elseif (one word)
k=k- end Similar changes to the if statement, can still use the
“break” statement to exit early if needed
as .m file
function
testFunction
^
No inputs or outputs
^
function
[x] = testFunction
^
Only 1 output called x
^
function
testFunction3(n)
^
Only 1 input called n
^
function
[y] = testFunction4(a,b,c)
^
3 inputs a, b, c and 1 output y
^
If the primary function has inputs call from commandline, if no inputs needed you can hit Run (or F5)
Make a .m script file the does the following ^
Save your script as practiceScript.m clc x = 3+4for i = 1:
i end
View the output ^
Add a ; to the end of the i;
line
^
After running the code type in
x
or
i^
in the
interactive mode command line ^
View the variable in the Workspace ^
Notice how the value is stored as a 2D matrix oftype double that has 1 row and 1 column.Remember MATLAB!
In this case MATLAB is more like Eclipse than IDLE ^
MATLAB has an easy to use debugger ^
Add a breakpoint to the start of your factorialTablecode (first line in the factorialTable function) ^
Step into the code
Comment line
Ctrl k
^
Uncomment line
Ctrl t
^
Select All/Auto Indent -
Ctrl a
Ctrl I
^
Run .m file
^
Autocomplete
Tab
^
Save
Ctrl s
^
Standard copy, cut, paste