MATLAB Fundamentals Quick Reference
MATLAB Fundamentals Quick Reference
MATLAB Fundamentals
1. Getting Started
Summary: Entering Commands
Creating Variables
Defining a variable y .
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 1/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Modifying Variables
You can use the Up (↑) and Down (↓) arrows on the keyboard to scroll through previous commands.
Cleaning Up
clc Clears the Command Window and moves the cursor to the upper left corner of the window.
Import Tool
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 2/50
5/11/2021 MATLAB Fundamentals - Quick Reference
You can use the Import Tool to interactively bring your data into MATLAB.
You can save and load MAT-files programmatically using the save and load commands.
save myData
Creates myData.mat containing current workspace variables.
save someFile x y
Instead of saving the entire MATLAB workspace, you can
selectively save individual variables. Saves x and y to
someFile.mat .
load myData
Loads variables from myData.mat into current workspace.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 3/50
5/11/2021 MATLAB Fundamentals - Quick Reference
>> doc
plot(Year,Germany)
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 4/50
5/11/2021 MATLAB Fundamentals - Quick Reference
plot(Australia,Germany,'mo')
Issuing the hold on command allows you to plot multiple data sets together on the same axes.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 5/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Textual information can be added to plots using separate annotation functions. All of these functions
take text input.
Example
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 6/50
5/11/2021 MATLAB Fundamentals - Quick Reference
v = axis
v =
0 12 0.1 0.9
xlim([-1 13])
ylim([-1 2])
axis tight
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 7/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Scripts can operate on the variables that are present in the base workspace before the script is run. Similarly, the
variables that are generated after the script is run are stored in the base workspace.
Use the controls in the MATLAB Toolstrip to create and run scripts.
Create Run
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 8/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Code sections allow you to organize your code and run sections of code independently. On the Live
Editor tab, in the Section section, click Section Break to create a new code section, or press
Ctrl+Alt+Enter.
You can use the controls on the Live Editor tab of the toolstrip to create, navigate to, and run
different sections.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 9/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Formatted Text
To insert a line of text, click the Text button in the Text section of the Live
Editor tab in the MATLAB Toolstrip.
Format the text using the formatting options provided in the Text section.
Comments
To create a comment, add % comment where you want to add more
information.
load AuDeMx
% Converts from US$/gal to US$/L
gal2lit = 0.2642; % conversion factor
Germany = gal2lit*Germany;
Australia = gal2lit*Australia;
Mexico = gal2lit*Mexico;
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 10/50
5/11/2021 MATLAB Fundamentals - Quick Reference
The saved file will closely resemble the live script when viewed in the Live Editor with output inline.
To share your code with users of previous MATLAB versions, you can save a live script as a plain
code file ( .m ). Users will be able to open and run your file, and any formatting will be converted to
comments with markup.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 11/50
5/11/2021 MATLAB Fundamentals - Quick Reference
c =
2 3 5 7
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 12/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Horizontal Concatenation
Vertical Concatenation
Separate elements
using a semicolon (;)
Combined Concatenation
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 13/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Calling Output
syntax
fun(m,n)
m-by-n
fun(n)
n-by-n
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 14/50
5/11/2021 MATLAB Fundamentals - Quick Reference
x = rand(260,1);
y = reshape(x,5,52);
Specify the dimensions for the new
array.
y = reshape(x,5,[]);
For convenience, you can also
leave one of the dimensions blank
when calling reshape and that
dimension will be calculated
automatically.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 15/50
5/11/2021 MATLAB Fundamentals - Quick Reference
s =
15 20 25
s =
15 20 25
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 16/50
5/11/2021 MATLAB Fundamentals - Quick Reference
v =
10 10 10 30 35
v =
15 10 5 30 35
Whether you're indexing into a matrix with scalar values or vector values, the format is always the
same.
output = M(2,3)
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 17/50
5/11/2021 MATLAB Fundamentals - Quick Reference
output = M(2,2:4)
output = M(2,:)
There are many operators that behave in element-wise manner, i.e., the operation is performed on each element of the
array individually.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 18/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Mathematical Functions
sin Sine
cos Cosine
log Logarithm
mod Modulus
Many more
Scalar Expansion
Operators
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponentiation
Arithmetic Operators
Operators
+ Addition
- Subtraction
.* Element-wise Multiplication
./ Element-wise Division
.^ Element-wise Exponentiation
Note that, for performing the arithmetic operations on two matrices, they should have identical dimensions.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 19/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Implicit Expansion
Operators
+ Addition
- Subtraction
.* Element-wise Multiplication
./ Element-wise Division
.^ Element-wise Exponentiation
Array operations can be performed on operands of different compatible sizes. Two arrays have compatible sizes if the size of each
dimension is either the same or one.
Matrix Multiplication
Matrix multiplication requires that the inner dimensions agree. The resultant matrix has the outer
dimensions.
Matrix “Division”
Expression Interpretation
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 20/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Function Description
Ignoring NaNs
avg = mean(v,'omitnan')
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 21/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Asum = sum(A)
Asum =
25 19 21
Many statistical functions accept an optional dimensional argument that specifies whether the
operation should be applied to columns independently (the default) or to rows.
>> M = mean(A,dim)
Outputs Inputs
M Vector of average values along A Matrix
dimension dim .
dim Dimension across which the mean
is taken.
1 : the mean of each column
2 : the mean of each row
Function Description
histogram Histogram
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 23/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Cell arrays of text are useful for annotating visualizations. Use curly braces, {} , to create a
cell array.
plot(x,y,linespec,Property1,Value1,Property2,Value2,Property3,Value3,...)
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 24/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Specifying Colors
You can use the plot function on a matrix to plot each column as a separate line in your plot.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 25/50
5/11/2021 MATLAB Fundamentals - Quick Reference
z =
0 0 0 0 0
z is a 5-by-5 matrix 0 0 -6 0 0
0 -3 1 3 0
0 0 8 1 0
0 0 0 0 0
surf(z)
The surf function plots each point z(j,k) over the point x= k and
y= j
x = 11:15;
y = 21:25;
surf(x,y,z)
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 26/50
5/11/2021 MATLAB Fundamentals - Quick Reference
~= Not equal
What are the indices of the elements that are true? find double
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 27/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Example:
idx = x > 4
Example:
9. Review Project I
EPL = readtable('EPLresults.xlsx');
The readtable function creates a table in
MATLAB from a data file.
teamWinsTable = table(team,wins)
teamWins =
team wins
The table function can create a table from ___________________ ____
workspace variables.
'Arsenal' 20
'Chelsea' 12
'Leicester City' 23
'Manchester United' 19
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 28/50
5/11/2021 MATLAB Fundamentals - Quick Reference
stats =
The array2table function can convert a
numeric array to a table. The VariableNames
Wins Draws Losses
property can be specified as a cell array of
____ _____ ______
names to include as variable names in the
table.
20 11 7
12 14 12
23 12 3
19 9 10
EPL = sortrows(EPL,'HomeWins');
The sortrows function sorts the data
in ascending order, by default.
EPL = sortrows(EPL,'HomeWins','descend');
Use the optional 'descend'
parameter to sort the list in
descending order.
EPL = sortrows(EPL,{'HomeWins','AwayWins'},'descend');
You can also sort on multiple
variables, in order, by specifying a cell
array of variable names.
summary(EPL)
You can also show summary statistics
for variables in a table.
EPL
EPL =
Team HW HD HL AW AD AL
___________________ __ __ __ __ __ __
'Leicester City' 12 6 1 11 6 2
'Arsenal' 12 4 3 8 7 4
Display the original table.
'Manchester City' 12 2 5 7 7 5
'Manchester United' 12 5 2 7 4 8
'Chelsea' 5 9 5 7 5 7
'Bournemouth' 5 5 9 6 4 9
'Aston Villa' 2 5 12 1 3 15
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 29/50
5/11/2021 MATLAB Fundamentals - Quick Reference
EPL(2:4,[1 2 5])
ans =
Team HW AW
Inside parenthesis, specify the
___________________ __ __
row numbers of the
'Arsenal' 12 8
observations and column
'Manchester City' 12 7
numbers of the table variables
'Manchester United' 12 7
you would like to select.
EPL(2:4,{'Team','HW','AW'})
EPL
EPL =
Team HW HD HL AW AD AL
___________________ __ __ __ __ __ __
Display the original table.
'Leicester City' 12 6 1 11 6 2
'Arsenal' 12 4 3 8 7 4
'Manchester City' 12 2 5 7 7 5
'Manchester United' 12 5 2 7 4 8
tw = EPL.HW + EPL.AW
tw =
You can use dot notation to
23
extract data for use in
20
calculations or plotting.
19
19
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 30/50
5/11/2021 MATLAB Fundamentals - Quick Reference
EPL =
Team HW HD HL AW AD AL TW
You can also use dot
___________________ __ __ __ __ __ __ __
notation to create new
'Leicester City' 12 6 1 11 6 2 23
variables in a table.
'Arsenal' 12 4 3 8 7 4 20
'Manchester City' 12 2 5 7 7 5 19
'Manchester United' 12 5 2 7 4 8 19
draws = EPL{:,{'HD','AD'}}
draws =
If you want to extract
6 6
multiple variables, you can
4 7
do this using curly braces.
2 7
5 4
You can use the writetable function to create a file from a table.
writetable(tableName,'myFile.txt')
The file format is based on the file extension, such as .txt , .csv , or .xlsx .
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 31/50
5/11/2021 MATLAB Fundamentals - Quick Reference
EPL
EPL =
Team Points
___________________ ______
'Leicester City' 81
'Arsenal' 71
'Aston Villa' 17
games
games =
Wins
____
Display the original tables.
23
20
3
teamInfo
teamInfo =
Team Manager
________________ _________________
'Arsenal' 'Arsène Wenger'
'Aston Villa' 'Eric Black'
'Leicester City' 'Claudio Ranieri'
[EPL games]
ans =
Team Points Wins
You can concatenate tables that
________________ ______ ____
are the same length but do not
'Leicester City' 81 23
share a common variable.
'Arsenal' 71 20
'Aston Villa' 17 3
EPL = join(EPL,teamInfo)
EPL =
Team Points Manager
___________________ ______ ___________________
The join function can combine
tables with a common variable.
'Leicester City' 81 'Claudio Ranieri'
'Arsenal' 71 'Arsène Wenger'
'Aston Villa' 17 'Eric Black'
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 32/50
5/11/2021 MATLAB Fundamentals - Quick Reference
EPL.Properties
ans =
Table Properties with properties:
Description: ''
UserData: []
DimensionNames: {'Row' 'Variable'}
Display the table properties.
VariableNames: {1×11 cell}
VariableDescriptions: {1×11 cell}
VariableUnits: {}
VariableContinuity: []
RowNames: {}
CustomProperties: No custom properties are set.
EPL.Properties.VariableNames
ans =
1×11 cell array
You can access an
Columns 1 through 4
individual property of
{'Team'} {'HomeWins'} {'HomeDraws'} {'HomeLosses'}
Properties using dot
Columns 5 through 8
notation.
{'HomeGF'} {'HomeGA'} {'AwayWins'} {'AwayDraws'}
Columns 9 through 11
{'AwayLosses'} {'AwayGF'} {'AwayGA'}
varNames = teamInfo.Properties.VariableNames
The variable varNames is a
cell array that contains
character arrays of different 'Team' 'Payroll_M__' 'Manager' 'ManagerHireDate'
lengths in each cell.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 33/50
5/11/2021 MATLAB Fundamentals - Quick Reference
varName(2)
Using parentheses to index
produces a cell array, not
the character array inside 'Payroll_M__'
the cell.
varName{2}
In order to extract the
contents inside the cell, you
should index using curly 'Payroll_M__'
braces, { } .
varName{2} = 'Payroll'
teamInfo
ans =
Manager ManagerHireDate
_________________ _______________
Dates are often automatically detected and brought in 'Rafael Benítez' 3/11/2016
as datetime arrays. 'Claudio Ranieri' 7/13/2015
'Ronald Koeman' 6/16/2014
'David Unsworth' 5/12/2016
'Slaven Bilić' 6/9/2015
sortrows(teamInfo,'ManagerHireDate')
ans =
Manager ManagerHireDate
_________________ _______________
Many functions operate on datetime arrays directly, 'Ronald Koeman' 6/16/2014
such as sortrows . 'Slaven Bilić' 6/9/2015
'Claudio Ranieri' 7/13/2015
'Rafael Benítez' 3/11/2016
'David Unsworth' 5/12/2016
t = datetime(1977,12,13)
You can create a datetime array using numeric
t =
inputs. The first input is year, then month, then day.
13-Dec-1977
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 34/50
5/11/2021 MATLAB Fundamentals - Quick Reference
ts = datetime([1903;1969],[12;7],[17;20])
seasonStart = datetime(2015,8,8)
seasonStart =
08-Aug-2015
seasonEnd =
17-May-2016
seasonLength =
Use subtraction to produce a duration variable.
6792:00:00
seasonLength = days(seasonLength)
Functions such as years and days can help seasonLength =
make better sense of the output. 283
seconds(5)
They can also create durations from a numeric ans =
value. 5 seconds
seasonLength = between(seasonStart,seasonEnd)
Use the between function to produce a context- seasonLength =
dependent calendarDuration variable. 9mo 9d
calmonths(2)
Create a calendar duration from a numeric input
ans =
with functions such as calmonths and
2mo
calyears .
You can learn more about datetime and duration functions in the documentation.
Create Date and Time Arrays
x = {'C','B','C','A','B','A','C'};
x is a cell array.
y = categorical(x);
nnz(x == 'C')
You can use == to create a logical array, and
ans =
count elements using nnz .
3
summary(y)
You can view category statistics using the
A B C
summary function.
2 2 3
y = mergecats(y,{'B','C'},'D')
You can view combine categories using the
y =
mergecats function.
D D D A D A D
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 36/50
5/11/2021 MATLAB Fundamentals - Quick Reference
2. Apply array operation to the matrix and the vector. The vector is
"expanded" as necessary to make the operation feasible.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 37/50
5/11/2021 MATLAB Fundamentals - Quick Reference
ismissing(x)
ans =
The ismissing function identifies only
1×7 logical array
the NaN elements by default.
0 1 0 0 0 0 1
ismissing(x,[-999,NaN])
Specifying the set of missing values ans =
ensures that ismissing identifies all the 1×7 logical array
missing elements. 0 1 0 0 1 0 1
xNaN = standardizeMissing(x,-999)
max cov
min mean
median
std
var
double NaN
single
datetime NaT
duration NaN
calendarDuration
categorical <undefined>
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 38/50
5/11/2021 MATLAB Fundamentals - Quick Reference
z = fillmissing(y,'method')
Interpolation assuming equal spacing of
observations.
z = fillmissing(y,'method','SamplePoints',x)
Interpolation with given observation
locations.
Method Meaning
'next' The missing value is the same as the next nonmissing value
in the data.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 39/50
5/11/2021 MATLAB Fundamentals - Quick Reference
z = movmean(y,k)
Mean calculated with a centered moving
k-point window.
z = movmean(y,[kb kf])
Mean calculated with a moving window
with kb points backward and kf points
forward from the current point.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 40/50
5/11/2021 MATLAB Fundamentals - Quick Reference
yyaxis left
plot(...)
yyaxis right
plot(...)
plotmatrix(data)
corrcoef(data)
ans =
1.0000 0.8243 0.1300 0.9519
Calculate linear correlation coefficients.
0.8243 1.0000 0.1590 0.9268
0.1300 0.1590 1.0000 0.2938
0.9519 0.9268 0.2938 1.0000
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 41/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Simple fitting
c = polyfit(x,y,n);
Fit polynomial to data.
yfit = polyval(c,xfit);
Evaluate fitted polynomial.
[c,~,scl] = polyfit(x,y,n);
Fit polynomial to data.
yfit = polyval(c,xfit,[],scl);
Evaluate fitted polynomial.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 42/50
5/11/2021 MATLAB Fundamentals - Quick Reference
disp('Message')
You can use disp to show output on the command window.
Message
warning('Missing data')
Missing data
msgbox('Analysis complete')
if condition_1
The condition_1 is evaluated as true or false .
code_1
If condition_1 is true , then the code_1 code block is executed.
elseif condition_2
code_2
Otherwise, the next case is tested. There can be any number of
cases.
elseif condition_3
code_3
else
If none of the cases are a match, then the code, code_e , in else
code_e
is executed.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 43/50
5/11/2021 MATLAB Fundamentals - Quick Reference
end
Always end the expression with the keyword end
switch expression
Evaluate expression to return a value.
case value 1
code_2
otherwise
If none of the cases are a match, then the code, code_3 , in
otherwise is executed. The otherwise block is optional.
code_3
end
Always end the expression with the keyword end
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 44/50
5/11/2021 MATLAB Fundamentals - Quick Reference
s = size(prices)
s =
19 10
[m,n] = size(prices)
m =
19
n =
Use size to find the dimensions of a matrix. 10
m = size(prices,1)
m =
19
n = size(prices,2)
n =
10
m = length(Year)
Use length when working with vectors where one of the m =
dimensions returned by size is 1 . 19
N = numel(prices)
Use numel to find the total number of elements in an array of any
N =
dimension.
190
while condition
The condition is a variable or expression that evaluates to true or
code
false . While condition is true , code executes. Once
end
condition becomes false, the loop ceases execution.
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 45/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Local functions:
Visible only within the file where they are defined.
Functions that are defined within a script.
Functions:
Visible to other script and function files.
Functions that are defined in separate files.
Summary: Workspaces
A function maintains its own workspace to store variables created in the function body.
foo.mlx
1. function y = foo(x)
a = 42; 2. a = sin(x);
b = foo(a); 3. x = x + 1;
4. b = sin(x);
5. y = a*b;
6. end
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 46/50
5/11/2021 MATLAB Fundamentals - Quick Reference
a 42 a -0.9165
b 0.7623 b -0.8318
x 43
y 0.7623
The search path, or path is a subset of all the folders in the file system. MATLAB can access all files
in the folders on the search path.
MATLAB can access the data and code files in the folders on the search path irrespective of the
current folder.
Calling Precedence
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 47/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Using functions reduces the possibility of variable name conflicts. However, you can still have
conflicts if a user-created function has the same name as a built-in MATLAB function or if a variable
has the same name as a function.
In MATLAB, there are rules for interpreting any named item. These rules are referred to as the
function precedence order. Most of the common reference conflicts can be resolved using the
following order:
1. Variables
2. Functions defined in the current script
3. Files in the current folder
4. Files on MATLAB search path
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 48/50
5/11/2021 MATLAB Fundamentals - Quick Reference
So, in the example shown above, the variable date is used instead of the function date .
elecData = readtable('elec_res.csv');
date = elecData.Dates(1);
date =
01-Jan-1990
nextDate = date + 1
nextDate =
02-Jan-1990
Use the MATLAB Code Analyzer messages shown in the Editor to identify and fix syntax errors.
Icon Meaning
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 49/50
5/11/2021 MATLAB Fundamentals - Quick Reference
Note that after you've identified and fixed any bugs, you should stop your debugging session, save
your changes, and clear all breakpoints before running your code again.
18. Conclusion
https://matlabacademy.mathworks.com/artifacts/quick-reference.html?course=mlbe&language=en&release=R2020b 50/50