Programming Fundamentals Using MATLAB Analyze Data And Develop Algorithms 1st Edition by Michael Weeks B09NZC2XC1 pdf download
Programming Fundamentals Using MATLAB Analyze Data And Develop Algorithms 1st Edition by Michael Weeks B09NZC2XC1 pdf download
https://ebookball.com/product/programming-fundamentals-using-
matlab-analyze-data-and-develop-algorithms-1st-edition-by-
michael-weeks-b09nzc2xc1-17618/
https://ebookball.com/product/data-structures-and-algorithms-in-
python-1st-edition-by-michael-goodrich-roberto-tamassia-michael-
goldwasser-isbn-9781118476734-1118476735-15762/
https://ebookball.com/product/problem-solving-in-data-structures-
and-algorithms-using-c-1st-edition-by-hemant-jain-
isbn-9352655915-9789352655915-15768/
https://ebookball.com/product/problem-solving-in-data-structures-
and-algorithms-using-c-1st-edition-by-hemant-jain-
isbn-1540407306-9781540407306-15866/
https://ebookball.com/product/javascript-data-structures-and-
algorithms-an-introduction-to-understanding-and-implementing-
core-data-structure-and-algorithm-fundamentals-1st-editon-by-
sammie-bae-isbn-1484239873-9781484239872-15798/
Web Animation using JavaScript Develop and Design 1st Edition by
Julian Shapiro ISBN 0134096703 9780134096704
https://ebookball.com/product/web-animation-using-javascript-
develop-and-design-1st-edition-by-julian-shapiro-
isbn-0134096703-9780134096704-16170/
Signal and System Analysis Using MATLAB 1st Edition by Luis Chaparro
0123747163 9780123747167
https://ebookball.com/product/signal-and-system-analysis-using-
matlab-1st-edition-by-luis-
chaparro-0123747163-9780123747167-17604/
https://ebookball.com/product/programming-fundamentals-a-modular-
structured-approach-using-c-1st-edition-by-kenneth-leroy-busbee-
isbn-1616100656-9781616100650-25036/
https://ebookball.com/product/robotics-vision-and-control-
fundamental-algorithms-in-matlab-2nd-edition-by-peter-
corke-3319544128-9783319544120-25276/
https://ebookball.com/product/data-structure-algorithms-using-c-
a-practical-implementation-1st-edition-by-sachi-nandan-mohanty-
pabitra-kumar-tripathy-9781119752035-1119752035-18754/
MATLAB®
Programming Fundamentals
R2022b
How to Contact MathWorks
Phone: 508-647-7000
Language
Syntax Basics
1
Continue Long Statements on Multiple Lines . . . . . . . . . . . . . . . . . . . 1-2
Program Components
2
MATLAB Operators and Special Characters . . . . . . . . . . . . . . . . . . . . 2-2
Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
String and Character Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
v
Compatible Array Sizes for Basic Operations . . . . . . . . . . . . . . . . . . 2-25
Inputs with Compatible Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Inputs with Incompatible Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
vi Contents
Fast Fourier Transform Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-86
Troubleshooting Operations with Comma-Separated Lists . . . . . . . . 2-86
Numeric Classes
4
Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Integer Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Creating Integer Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Arithmetic Operations on Integer Classes . . . . . . . . . . . . . . . . . . . . . 4-4
Largest and Smallest Values for Integer Classes . . . . . . . . . . . . . . . . 4-4
vii
Display Format for Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18
viii Contents
Frequently Asked Questions About String Arrays . . . . . . . . . . . . . . . 6-58
Why Does Using Command Form With Strings Return An Error? . . 6-58
Why Do Strings in Cell Arrays Return an Error? . . . . . . . . . . . . . . . 6-59
Why Does length() of String Return 1? . . . . . . . . . . . . . . . . . . . . . . 6-59
Why Does isempty("") Return 0? . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-60
Why Does Appending Strings Using Square Brackets Return Multiple
Strings? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-61
ix
Compare Dates and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33
Categorical Arrays
8
Create Categorical Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
x Contents
Tables
9
Create Tables and Assign Data to Them . . . . . . . . . . . . . . . . . . . . . . . 9-2
Timetables
10
Create Timetables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
xi
Retime and Synchronize Timetable Variables Using Different
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14
Structures
11
Structure Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Create Scalar Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Access Values in Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Index into Nonscalar Structure Array . . . . . . . . . . . . . . . . . . . . . . . 11-4
Cell Arrays
12
What Is a Cell Array? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
xii Contents
Add Cells to Cell Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
Function Handles
13
Create Function Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
What Is a Function Handle? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Creating Function Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3
Arrays of Function Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4
Saving and Loading Function Handles . . . . . . . . . . . . . . . . . . . . . . 13-4
Dictionaries
14
Map Data with Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Map Containers
15
Overview of Map Data Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2
xiii
Description of Map Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
Properties of Map Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
Methods of Map Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
xiv Contents
Using Objects
17
Copying Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Two Copy Behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Handle Object Copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Value Object Copy Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Handle Object Copy Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-3
Testing for Handle or Value Class . . . . . . . . . . . . . . . . . . . . . . . . . . 17-5
Scripts
19
Create Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2
xv
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-4
Unsupported Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-5
xvi Contents
Live Code File Format (.mlx) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-58
Benefits of Live Code File Format . . . . . . . . . . . . . . . . . . . . . . . . . 20-58
Source Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-58
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-89
Function Basics
21
Create Functions in Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-2
Syntax for Function Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-2
Contents of Functions and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-3
End Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-4
xvii
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-20
What Are Anonymous Functions? . . . . . . . . . . . . . . . . . . . . . . . . . 21-20
Variables in the Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-21
Multiple Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-21
Functions with No Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-22
Functions with Multiple Inputs or Outputs . . . . . . . . . . . . . . . . . . 21-22
Arrays of Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 21-23
xviii Contents
Function Arguments
22
Find Number of Function Arguments . . . . . . . . . . . . . . . . . . . . . . . . 22-2
xix
Presenting MATLAB Code
24
Publish and Share MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2
Create and Share Live Scripts in the Live Editor . . . . . . . . . . . . . . . 24-2
Publish MATLAB Code Files (.m) . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2
Add Help and Create Documentation . . . . . . . . . . . . . . . . . . . . . . . 24-4
Check Code for Errors and Warnings Using the Code Analyzer . . . 25-5
Enable Continuous Code Checking . . . . . . . . . . . . . . . . . . . . . . . . . 25-5
View Code Analyzer Status for File . . . . . . . . . . . . . . . . . . . . . . . . . 25-5
View Code Analyzer Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-6
Fix Problems in Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-7
Create a Code Analyzer Message Report . . . . . . . . . . . . . . . . . . . . . 25-8
Adjust Code Analyzer Message Indicators and Messages . . . . . . . . 25-9
Understand Code Containing Suppressed Messages . . . . . . . . . . . 25-11
Understand the Limitations of Code Analysis . . . . . . . . . . . . . . . . 25-12
Enable MATLAB Compiler Deployment Messages . . . . . . . . . . . . . 25-14
xx Contents
Edit and Format Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-16
Column Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-16
Change Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-16
Automatically Complete Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-16
Refactor Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-17
Indent Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-17
Fold Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-18
Change the Right-Side Text Limit Indicator . . . . . . . . . . . . . . . . . . 25-19
Programming Utilities
26
Identify Program Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2
Simple Display of Program File Dependencies . . . . . . . . . . . . . . . . 26-2
Detailed Display of Program File Dependencies . . . . . . . . . . . . . . . 26-2
Dependencies Within a Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2
xxi
Run Older P-Code Files on Later Versions of MATLAB . . . . . . . . . . . 26-9
xxii Contents
Software Development
Error Handling
28
Exception Handling in a MATLAB Application . . . . . . . . . . . . . . . . . 28-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-2
Getting an Exception at the Command Line . . . . . . . . . . . . . . . . . . 28-2
Getting an Exception in Your Program Code . . . . . . . . . . . . . . . . . . 28-3
Generating a New Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-3
xxiii
Program Scheduling
29
Schedule Command Execution Using Timer . . . . . . . . . . . . . . . . . . . 29-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-2
Example: Displaying a Message . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-2
Performance
30
Measure the Performance of Your Code . . . . . . . . . . . . . . . . . . . . . . 30-2
Overview of Performance Timing Functions . . . . . . . . . . . . . . . . . . 30-2
Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-2
Time Portions of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-2
The cputime Function vs. tic/toc and timeit . . . . . . . . . . . . . . . . . . . 30-2
Tips for Measuring Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-3
Preallocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-14
Preallocating a Nondouble Matrix . . . . . . . . . . . . . . . . . . . . . . . . 30-14
Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-16
Using Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-16
Array Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-17
Logical Array Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-18
Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30-19
Ordering, Setting, and Counting Operations . . . . . . . . . . . . . . . . . 30-20
Functions Commonly Used in Vectorization . . . . . . . . . . . . . . . . . 30-21
xxiv Contents
Background Processing
31
Asynchronous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-2
Asynchronous Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-2
Background Workers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-4
Memory Usage
32
Strategies for Efficient Use of Memory . . . . . . . . . . . . . . . . . . . . . . . 32-2
Use Appropriate Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-2
Avoid Temporary Copies of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-3
Reclaim Used Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32-4
xxv
Custom Help and Documentation
33
Create Help for Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-2
Help Text from the doc Command . . . . . . . . . . . . . . . . . . . . . . . . . . 33-2
Custom Help Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33-3
Projects
34
Create Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-2
What Are Projects? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-2
Create Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-2
Open Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-2
Set up Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-3
Add Files to Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-5
Other Ways to Create Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34-6
xxvi Contents
Determine Order for Resolving Conflicts Using Dependency Analyzer
.................................................... 34-13
xxvii
Manage Open Files When Closing a Project . . . . . . . . . . . . . . . . . 34-61
xxviii Contents
Move, Rename, or Delete Files Under SVN Source Control . . . . . . 35-27
xxix
Check Files In and Out from MSSCCI Source Control . . . . . . . . . . 35-57
Check Files Into Source Control . . . . . . . . . . . . . . . . . . . . . . . . . . 35-57
Check Files Out of Source Control . . . . . . . . . . . . . . . . . . . . . . . . 35-57
Undoing the Checkout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35-58
Unit Testing
36
Write Test Using Live Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-3
xxx Contents
Test Suite Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-33
Test Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-33
Test Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-34
Programmatic Access of Test Diagnostics . . . . . . . . . . . . . . . . . . . 36-34
Test Runner Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-35
xxxi
Programmatically Access Test Diagnostics . . . . . . . . . . . . . . . . . . . 36-96
Write Tests That Use App Testing and Mocking Frameworks . . . 36-158
Create App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-158
Test App With Manual Intervention . . . . . . . . . . . . . . . . . . . . . . . 36-159
Create Fully Automated Test . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-160
xxxii Contents
Test Performance Using Scripts or Functions . . . . . . . . . . . . . . . . 36-167
xxxiii
Travis CI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-222
Other Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36-222
Build Automation
37
Overview of MATLAB Build Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37-2
Create Plan with Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37-2
Run Tasks in Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37-3
xxxiv Contents
Initialize Properties and Setup One-Time Calculations . . . . . . . . . . . . . 38-18
xxxv
Inputs and Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38-50
Using ~ as an Input Argument in Method Definitions . . . . . . . . . . . . . . 38-50
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38-50
Text Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38-51
Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38-51
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38-52
Create New System Objects for File Input and Output . . . . . . . . . . . . . 38-70
xxxvi Contents
Language
37
1
Syntax Basics
The start and end quotation marks for a character vector must appear on the same line. For example,
this code returns an error, because each line contains only one quotation mark:
x = [1.23...
4.56];
is the same as
x = [1.23 4.56];
1-2
Name=Value in Function Calls
Use the name=value syntax to help identify name-value arguments for functions and to clearly
distinguish names from values in lists of name-value arguments.
Most functions and methods support both syntaxes, but there are some limitations on where and how
the name=value syntax can be used:
Mixing name,value and name=value syntaxes: The recommended practice is to use only one
syntax in any given function call. However, if you do mix name=value and name,value syntaxes
in a single call, all name=value arguments must appear after the name,value arguments. For
example, plot(x,y,"Color","red",LineWidth=2) is a valid combination, but
plot(x,y,Color="red","LineWidth",2) errors.
• Using positional arguments after name-value arguments: Some functions have positional
arguments that appear after name-value arguments. For example, this call to the verifyEqual
method uses the RelTol name-value argument, followed by a string input:
verifyEqual(testCase,1.5,2,"RelTol",0.1,...
"Difference exceeds relative tolerance.")
Using the name=value syntax (RelTol=0.1) causes the statement to error. In cases where a
positional argument follows name-value arguments, use the name,value syntax.
• Names that are invalid variable names: Name-value arguments with names that are invalid
MATLAB variable names cannot be used with the name=value syntax. See “Variable Names” on
page 1-5 for more info. For example, a name-value argument like "allow-empty",true errors
if passed as allow-empty=true. Use the name,value syntax in these cases.
Function authors do not need to code differently to support both the name,value and name=value
syntaxes. For information on authoring functions that accept name-value arguments, see “Name-Value
Arguments” on page 27-11.
1-3
1 Syntax Basics
This example shows how to ignore specific outputs from a function using the tilde (~) operator.
helpFile = which('help');
[helpPath,name,ext] = fileparts(helpFile);
The current workspace now contains three variables from fileparts: helpPath, name, and ext. In
this case, the variables are small. However, some functions return results that use much more
memory. If you do not need those variables, they waste space on your system.
If you do not use the tilde operator, you can request only the first N outputs of a function (where N is
less than or equal to the number of possible outputs) and ignore any remaining outputs. For example,
request only the first output, ignoring the second and third.
helpPath = fileparts(helpFile);
If you request more than one output, enclose the variable names in square brackets, []. The
following code ignores the output argument ext.
[helpPath,name] = fileparts(helpFile);
To ignore function outputs in any position in the argument list, use the tilde operator. For example,
ignore the first output using a tilde.
[~,name,ext] = fileparts(helpFile);
You can ignore any number of function outputs using the tilde operator. Separate consecutive tildes
with a comma. For example, this code ignores the first two output arguments.
[~,~,ext] = fileparts(helpFile);
See Also
More About
• “Ignore Inputs in Function Definitions” on page 22-10
1-4
Variable Names
Variable Names
In this section...
“Valid Names” on page 1-5
“Conflicts with Function Names” on page 1-5
Valid Names
A valid variable name starts with a letter, followed by letters, digits, or underscores. MATLAB is case
sensitive, so A and a are not the same variable. The maximum length of a variable name is the value
that the namelengthmax command returns.
You cannot define variables with the same names as MATLAB keywords, such as if or end. For a
complete list, run the iskeyword command.
Avoid creating variables with the same name as a function (such as i, j, mode, char, size, and
path). In general, variable names take precedence over function names. If you create a variable that
uses the name of a function, you sometimes get unexpected results.
Check whether a proposed name is already in use with the exist or which function. exist returns
0 if there are no existing variables, functions, or other artifacts with the proposed name. For example:
exist checkname
ans =
0
If you inadvertently create a variable with a name conflict, remove the variable from memory with the
clear function.
Another potential source of name conflicts occurs when you define a function that calls load or eval
(or similar functions) to add variables to the workspace. In some cases, load or eval add variables
that have the same names as functions. Unless these variables are in the function workspace before
the call to load or eval, the MATLAB parser interprets the variable names as function names. For
more information, see:
1-5
1 Syntax Basics
See Also
clear | exist | iskeyword | namelengthmax | which | isvarname
1-6
Case and Space Sensitivity
In MATLAB code, use an exact match with regard to case for variables, files, and functions. For
example, if you have a variable, a, you cannot refer to that variable as A. It is a best practice to use
lowercase only when naming functions. This is especially useful when you use both Microsoft®
Windows® and UNIX®1 platforms because their file systems behave differently with regard to case.
When you use the help function, the help displays some function names in all uppercase, for
example, PLOT, solely to distinguish the function name from the rest of the text. Some functions for
interfacing to Oracle® Java® software do use mixed case and the command-line help and the
documentation accurately reflect that.
Spaces
Blank spaces around operators such as -, :, and ( ), are optional, but they can improve readability.
For example, MATLAB interprets the following statements the same way.
y = sin (3 * pi) / 2
y=sin(3*pi)/2
However, blank spaces act as delimiters in horizontal concatenation. When defining row vectors, you
can use spaces and commas interchangeably to separate elements:
A = [1, 0 2, 3 3]
A =
1 0 2 3 3
Because of this flexibility, check to ensure that MATLAB stores the correct values. For example, the
statement [1 sin (pi) 3] produces a much different result than [1 sin(pi) 3] does.
[1 sin (pi) 3]
[1 sin(pi) 3]
ans =
1 UNIX is a registered trademark of The Open Group in the United States and other countries.
1-7
1 Syntax Basics
MATLAB has two ways of calling functions, called function syntax and command syntax. This page
discusses the differences between these syntax formats and how to avoid common mistakes
associated with command syntax.
For introductory information on calling functions, see “Calling Functions”. For information related to
defining functions, see “Create Functions in Files” on page 21-2.
In function syntax, inputs can be data, variables, and even MATLAB expressions. If an input is data,
such as the numeric value 2 or the string array ["a" "b" "c"], MATLAB passes it to the function
as-is. If an input is a variable MATLAB will pass the value assigned to it. If an input is an expression,
like 2+2 or sin(2*pi), MATLAB evaluates it first, and passes the result to the function. If the
functions has outputs, you can assign them to variables as shown in the example syntax above.
Command syntax is simpler but more limited. To use it, separate inputs with spaces rather than
commas, and do not enclose them in parentheses.
With command syntax, MATLAB passes all inputs as character vectors (that is, as if they were
enclosed in single quotation marks) and does not assign outputs to variables. To pass a data type
other than a character vector, use the function syntax. To pass a value that contains a space, you have
two options. One is to use function syntax. The other is to put single quotes around the value.
Otherwise, MATLAB treats the space as splitting your value into multiple inputs.
If a value is assigned to a variable, you must use function syntax to pass the value to the function.
Command syntax always passes inputs as character vectors and cannot pass variable values. For
example, create a variable and call the disp function with function syntax to pass the value of the
variable:
A = 123;
disp(A)
123
You cannot use command syntax to pass the value of A, because this call
disp A
1-8
Choose Command Syntax or Function Syntax
is equivalent to
disp('A')
and returns
filename = 'accounts.txt';
A = int8(1:8);
B = A;
or
Some functions expect character vectors for variable names, such as save, load, clear, and whos.
For example,
requests information about variable X in the example file durer.mat. This command is equivalent to
whos('-file','durer.mat','X')
ls ./d
1-9
1 Syntax Basics
This could be a call to the ls function with './d' as its argument. It also could represent element-
wise division on the array ls, using the variable d as the divisor.
If you issue this statement at the command line, MATLAB can access the current workspace and path
to determine whether ls and d are functions or variables. However, some components, such as the
Code Analyzer and the Editor/Debugger, operate without reference to the path or workspace. When
you are using those components, MATLAB uses syntactic rules to determine whether an expression is
a function call using command syntax.
In general, when MATLAB recognizes an identifier (which might name a function or a variable), it
analyzes the characters that follow the identifier to determine the type of expression, as follows:
ls =d
• An open parenthesis after an identifier implies a function call. For example:
ls('./d')
• Space after an identifier, but not after a potential operator, implies a function call using command
syntax. For example:
ls ./d
• Spaces on both sides of a potential operator, or no spaces on either side of the operator, imply an
operation on variables. For example, these statements are equivalent:
ls ./ d
ls./d
Therefore, MATLAB treats the potentially ambiguous statement ls ./d as a call to the ls function
using command syntax.
The best practice is to avoid defining variable names that conflict with common functions, to prevent
any ambiguity.
See Also
“Calling Functions” | “Create Functions in Files” on page 21-2
1-10
Resolve Error: Undefined Function or Variable
Issue
You may encounter the following error message, or something similar, while working with functions
or variables in MATLAB:
These errors usually indicate that MATLAB cannot find a particular variable or MATLAB program file
in the current directory or on the search path.
Possible Solutions
Verify Spelling of Function or Variable Name
One of the most common causes is misspelling the function or variable name. Especially with longer
names or names containing similar characters (such as the letter l and numeral one), it is easy to
make mistakes and hard to detect them.
Often, when you misspell a MATLAB function, a suggested function name appears in the Command
Window. For example, this command fails because it includes an uppercase letter in the function
name:
accumArray
When this happens, press Enter to execute the suggested command or Esc to dismiss it.
Object methods are typically called using function syntax: for instance method(object,inputs).
Alternatively, they can be called using dot notation: for instance object.method(inputs). One
common error is to mix these syntaxes. For instance, you might call the method using function syntax,
but to provide inputs following dot notation syntax and leave out the object as an input: for instance,
method(inputs). To avoid this, when calling an object method, make sure you specify the object
first, either through the first input of function syntax or through the first identifier of dot notation.
When you write a function, you establish its name when you write its function definition line. This
name should always match the name of the file you save it to. For example, if you create a function
named curveplot,
then you should name the file containing that function curveplot.m. If you create a pcode file for
the function, then name that file curveplot.p. In the case of conflicting function and file names, the
file name overrides the name given to the function. In this example, if you save the curveplot
1-11
1 Syntax Basics
function to a file named curveplotfunction.m, then attempts to invoke the function using the
function name will fail:
curveplot
Undefined function or variable 'curveplot'.
If you encounter this problem, change either the function name or file name so that they are the
same.
To Locate the file that defines this function, use the MATLAB Find Files utility as follows:
1
On the Home tab, in the File section, click Find Files.
2 Under Find files named, enter *.m
3 Under Find files containing text, enter the function name.
4 Click the Find button
If you are unable to use a built-in function from MATLAB or its toolboxes, make sure that the function
is installed and is the correct version.
If you do not know which toolbox contains the function you need, search for the function
documentation at https://www.mathworks.com/help. The toolbox name appears at the top of the
function reference page. Alternatively, for steps to identify toolboxes that a function depends on, see
“Identify Program Dependencies” on page 26-2.
Once you know which toolbox the function belongs to, use the ver function to see which toolboxes
are installed on the system from which you run MATLAB. The ver function displays a list of all
currently installed MathWorks® products. If you can locate the toolbox you need in the output
displayed by ver, then the toolbox is installed. If you cannot, you need to install it in order to use it.
For help with installing MathWorks products, see “Install License Manager on License Server”.
1-12
Another Random Scribd Document
with Unrelated Content
less of lip-worship than their predecessors, Sejanus, Pallas, and
Narcissus.
There seems indeed to have risen, at least in the later years of
this principate, a marked separation between the court and the
nobility; the senators shrank from the presence of a man who so
openly degraded his name and lineage; they fled the contact of his
dissolute associates; they entered into widespread conspiracies
against him, to which they had never been provoked by the tyranny
of his predecessors; and they had the merit of incurring his petulant
displeasure, with many a threat to extinguish their order altogether,
and give the provinces to his knights and freedmen. “I hate you,
Cæsar,” exclaimed the most refined of his flatterers, “because you
are a senator.” Accordingly this emperor, notwithstanding the pomp
and splendour of his shows and public appearances, seems to have
been left for the most part to the mercenary attendance of his
personal favourites, protected only by a troop of spies and
informers, and the vilest portion of the pampered populace, from the
general detestation of respectable citizens.[18]
The cruelties of Nero’s later years were the more fearful, perhaps,
from their apparent caprice. He had no politic object, such as may
be ascribed to Tiberius—of policy indeed he was incapable. Except
that his murders were commonly prompted by need or fear, and
therefore fell oftenest on the rich and powerful, it can hardly be said
that one class suffered from them more terribly than another.
Undoubtedly, however, the senate furnished the longest list of
victims to the tyrant’s barbarity. The greatest and noblest were the
most exposed to the prince’s evil eye, which lighted upon them
equally at public ceremonials and private receptions, and marked
them for immolation at every fresh burst of ill-humour. The
proscriptions to which this body was subjected under the four
Claudian Cæsars reduced its numbers considerably, more, indeed, it
may be imagined, than was replaced by the ordinary sources of
replenishment. Claudius, among his other reforms, sought to restore
the balance by a special measure, and such was probably the object
of his revision of the senate, the last of the kind we read of; but the
decline must have been accelerated under Nero, without check or
counteraction. Nero, reckless equally of the past and future, felt no
anxiety to maintain the numbers of that historic assembly; and the
various causes, besides the emperor’s tyranny, which were always at
work to extinguish the oldest families, must have acted with terrible
force on the effete branches of the ancient aristocracy. But if its
numbers were reduced, no less were its employments also
diminished.
Under the lax discipline of Nero and of Tigellinus appointments to
office abroad would be the prize of interest and favour, guided
neither by routine nor by discretion; at home the boards and
commissions established by Augustus would fall into disuse.
Pensions and sinecures, though such corruptions are not known to
us at Rome by name, would doubtless abound, but of real business
there would be less and less. Intrigue and peculation would flourish
in a soil protected from the air of public opinion, and the strong
hand of central control.
The passive endurance which marked the conduct of the senate
under the imperial persecutions seems to bespeak a consciousness
of its own guilt towards the state, and it compounded for its
monopoly of unquestioned abuses by bowing to the yoke of a
jealous and domineering master. We discover in Seneca no reliance
on the senate. He never speaks of it as a living guardian of the
virtues of Roman society. And yet, notwithstanding this
abandonment of its high prerogative, it still exercised a moral power.
Its mere title could awaken associations which thrilled from pulse to
pulse. It was still regarded by the men of ancient name and blood as
the true head or heart of the empire, rather than the upstart
Claudius or Domitius, who might wear the purple and wield the
sword. To the men of words and phrases the emperor was still an
accident,—the senate was an eternal fact,—at a time when rhetoric
might make revolutions, though it could not regenerate society. To
them it was still the symbol of liberty, at a time when liberty and
Cæsar were regarded as two gladiators sword in hand, pitted
against each other in mortal combat. This venerable image of its
ancient majesty was preserved to it by the proscriptions themselves
by which it suffered; for as often as a murdered Scribonius or
Pompeius was replaced in the chairs of office by a Rubellius, a
Lollius, or a Vitellius, the principle of its vitality was in fact
invigorated by the infusion of new plebeian blood.
As fast indeed as the tyrant’s exigencies required the confiscation
of the great estates of nobles, and the overthrow of great families,
his caprice and favour were elevating new men from the inferior
orders to succeed to their distinctions, and to rival them in their vast
possessions. Nero never kept his money. All he robbed, all he
extorted, was squandered as abruptly as it was acquired, and
shrewd Roman money-makers were always waiting upon his
necessities, and sweeping the properties of his victims into their
stores for a small part of their value in specie. Of the vast sums
amassed by the freedmen of Claudius and his successors some
records have been preserved to us; but the freedmen were a class
peculiarly obnoxious to remark, and it is probable that knights and
senators were at the same time, and by similar compliances, raising
fortunes not less enormous, who have escaped the designating
finger of history. Though the grinding processes to which the
colossal properties of the nobles were subjected must on the whole
have broken down the average amount of their revenues far below
the rate at which it figured under the republic and the first Cæsars,
we must not suppose that the current set all in one direction, or that
the age of Claudius and Nero was not also a period of great private
accumulations. The wealth of individuals and of the upper ranks at
Rome generally reached perhaps its greatest height at this
culminating epoch.
Descending, however, from the high places of the Roman world,
we find beneath them a commonalty suffering also a social
revolution, undergoing a rapid transition, and presenting the
elements of two rival classes, or even hostile camps, in the bosom of
the city. The clients and retainers of the old nobility, whether freed
or freeborn, still formed the pith and marrow of the commonwealth;
still leaning their humble tenements against the great lords’
mansions, still respecting them as their patrons and advisers, still
attending their levees, and waiting for the daily complement of the
sportula at their doors, they regarded them as the real chiefs of the
state, and held them equals of Cæsar himself. The death or exile of
their august protector might strike them with surprise and
indignation; but when they looked around and counted their
numbers, they felt their own insignificance, and quailed beneath the
blow in silence. They saw that there was growing up beside them a
vast class of patronless proletaries, the scum of the streets and
lanes, slaves, freedmen, foreigners, men of base trades and
infamous employments, or of ruined fortunes, who, having none but
Cæsar himself to depend on, threw the weight of their numbers in
his scale, and earned his doles and entertainments by lavish
caresses, and deeds corresponding to their promises. These have
been called the lazzaroni of ancient Rome; in idleness, indeed, and
mendicancy they deserve the title; but they were the paupers of a
world-wide empire, and the crumbs on which they fed fell from the
tables of kings and princes. The wealth of millions of subjects was
lavished on these mendicant masters. For days together, on the oft-
recurring occasion of an imperial festival, valuables of all kinds were
thrown pell-mell among them, rare and costly birds were lavished
upon them by thousands, provisions of every kind, costly robes, gold
and silver, pearls and jewels, pictures, slaves and horses, and even
tamed wild beasts. At last, in the progress of this wild profusion,
ships, houses, and estates were bestowed by lottery on these
waiters upon Cæsar’s providence.
This extravagance was retained without relaxation throughout
Nero’s reign; had he paused in it for a moment the days of his power
would have been few. The rumour that he was about to quit Rome
for the East caused murmurs of discontent, and forced him to
consult the gods, and pretend to be deterred by signs of their
displeasure from carrying his design into effect. When at last, as we
shall see, he actually visited Greece, he left behind him a
confidential minister, to keep the stream of his liberality flowing, at
whatever cost and by whatever measures of spoliation. Absent or
present, he flung to these pampered supporters a portion of every
confiscated fortune; the emperor and his people hunted together,
and the division of the prey was made apparently to the satisfaction
of both equally. Capricious as were the blows he dealt around him,
this class alone he took care never to offend, and even the charge of
firing the city fell lightly on the ears of the almost houseless
multitude, whose losses at least had been fully compensated by
plunder. The clients of the condemned nobles were kept effectually
in check by this hungry crowd, yelling over every carcass with the
prospect of a feast. Nero, in the height of his tyranny and alarm, had
no need to increase the number of his prætorians; the lazzaroni of
Rome were a bodyguard surrounding him in every public place, and
watching the entrances and exits at his palace gates.
Such were the chief distinctions of class at this period among the
Roman people, the so-called lords of mankind, and beyond them lay
the great world of the provincials, their subjects. But if these were
subjects in name, they were now become in fact the true Roman
people; they alone retained real freedom of action within the limits
of the empire; they were allowed to labour, and they enjoyed the
bulk at least of the fruits of industry; they rarely saw the hateful
presence of the emperor, and knew only by report the loathsome
character of his courtiers and their orgies. And if sometimes the
thunderbolt might fall among them, it struck only the highest
eminences; the multitude was safe as it was innocent. The extortion
of the proconsul in the province was not to be compared in
wantonness or severity with the reckless pillage of the emperor in
the capital, nearer home. The petulance of a proconsul’s wife was
hardly tolerated abroad, while at home the prince’s worst atrocities
were stimulated by female cupidity. The taxation of the subject, if
heavier in some respects than that of the citizen, was at least
tolerably regular; the extraordinary demands which Nero made
towards the rebuilding of Rome were an exception to the routine of
fiscal imposts. But, above all, the provincials had changed place with
their masters in being now the armed force of the empire.
The citizen had almost ceased to wield
the sword. Even the prætorians were
recruited from Italy, not from Rome herself;
and among them thousands were doubtless
foreign born, the offscourings of the
provinces, who had thrown themselves on
the shores of Italy to seek their fortunes in
a sphere abandoned by the indolence of
their masters. The prætorian, like the
proletary of the city, was highly cherished
by the emperor. He had his rights and
privileges which raised him above every
other military conscript. While the legionary
served at ten asses a day for thirty or forty
years, exposed to the risks of war, fatigue,
and climate, nor regained his liberty and
safety till age had blanched his hair and
stiffened his limbs, the prætorian lived
quietly at Rome under the lax discipline of a
stative camp; he enjoyed double pay, and Roman Cavalryman
claimed dismissal after sixteen years’
service. He had his regular dole of corn, his
occasional largess, his extraordinary donative whenever an
opportunity had occurred to prove his fidelity. Tiberius, on the fall of
Sejanus, had given him 1000 asses; Claudius had paid for the purple
with a sum of 150,000,000 of sesterces; Nero had followed these
examples, and established them as the rule of the succession; on
the overthrow of Piso’s conspiracy he had requited his prætorians
with 2000 sesterces apiece. Thus caressed, the favoured cohorts of
the guard became the firmest support of the prince, their creature,
and under the sway of military traditions, from which even they were
not exempt, regarded their oath of allegiance with strict fidelity. This
fidelity, indeed, they considered due to the imperator himself rather
than to the senate and people, whom they equally despised; they
were satisfied with the power of making the Cæsars, and as yet
were far from conceiving in their minds the idea of unmaking them
again.
But far different was the case with the legions in the provinces.
The legionary was still less Roman than the prætorian. If to a great
extent the recruits for the frontier camps were still levied from the
class which possessed the nominal franchise of the city, yet these
citizens were themselves, for the most part, new-enfranchised
provincials; they had received Latin or Roman rights as a boon from
the emperor, or perhaps purchased them for the sake of their fiscal
immunities. Romans in blood or even Italians the legionaries no
longer were. They were supported by ample levies of auxiliaries,
avowedly of foreign extraction, generally transferred from their
homes to a camp at a far distant station; Silures and Brigantes to
the Danube; Tungri and Suevi to the borders of Wales; Iberians to
the Euphrates; Numidians to the Rhine. Amidst the clang of
dissonant languages that resounded through the camp the Latin was
the least heard and understood.
Yet the word of command was still Roman, and the chief officers
were Roman also; the affections of this soldiery, long estranged from
the emperor and the senate, were attached to the tribune and the
legatus; and the murmurs of the nobles at home, which moved the
sympathy of their kinsmen on the frontier, met a deep response in
the devotion of these sons of the eagles to their accustomed
leaders. The vast distance of the great camps of the empire from
one another, and the frequent change of their officers, together with
the motives of jealousy which the emperors nourished between
them, helped to prevent these legions from joining in a common
cause when disaffection menaced an outbreak in any particular
quarter. They made some partial attempts to supplant the
prætorians by carrying one of their own chiefs to power; but every
endeavour of the kind had been hitherto baffled by the want of
concert among them. More success was to attend the efforts in the
near future.
In the year 63 a.d., Nero, we are told, was preparing to visit the
East in person. Some indeed asserted that his object was only to
behold the wonders of Egypt, and the interest of the citizens was
just then directed towards that mysterious region by the discoveries
of an exploring party, which had recently ascended the Nile nine
hundred miles above Syene. Others believed that he had no
intention of proceeding beyond Greece; but it seems probable that
his views were really more extensive, and that he contemplated
throwing himself into the quarters of the Syrian legions, and
checking by his presence the ambition of the proconsul, perhaps
seizing an opportunity to overthrow him. But, whatever Nero’s
project may have been, it was frustrated, as we have seen, by the
occurrence of the fire at Rome. The affairs of the next three years
have been already related: the conspiracies which were concerted
against the emperor at home, his redoubled efforts to secure the
favour of the populace, and his cruel precaution of destroying every
man of eminence who might become the centre of fresh
machinations to his prejudice. In the year 66 he at last found leisure
to execute his scheme of travel, so far, at least, as to visit Greece;
where he presented himself at the public spectacles, and gratified
his passion for dancing and singing before promiscuous
assemblages, with still less reserve than at home. All the states
which held musical contests had hastened, even before his arrival, to
humour him with the offer of their prizes, and Nero had received
their envoys with the highest honours, and invited them to his table.
When one of them begged him to give a specimen of his singing,
and his skill was rapturously applauded, he declared that the Greeks
alone had ears, and alone deserved the honour of hearing him.
NERO IN GREECE
Nor was the gallant Corbulo the tyrant’s only victim. At the same
time he summoned two brothers, Rufus and Proculus, of the great
Scribonian house, who commanded in the two Germanies, to meet
him in Greece, under pretence of conferring with them on state
affairs. The summons was in fact a recall, and the pretence which
accompanied it could hardly have deceived them; yet they too
obeyed with the same alacrity as Corbulo, and fell, perhaps not
unwittingly, into the same snare. Some specific charges were laid
against them; but no opportunity was given them of meeting them,
nor were they allowed to see the emperor. They killed themselves in
despair.
Although, during his sojourn in Greece, Nero traversed the
province in every direction, it was observed that he refrained from
visiting either Athens or Sparta. With respect to the city of Lycurgus
it was affirmed merely that he kept aloof from it lest the austerity of
its usages should prove irksome to him; but he dared not enter the
abode of the Erinyes, from dread of their vengeance on his crimes.
Another account said that he was deterred from initiation into the
mysteries of Eleusis, which was denied, under direst imprecations, to
the impious and impure. Of these awful legends of Grecian antiquity
but a faint and confused echo resounded in Italy. To the Latin or the
Sabine it little mattered whether the murderer shrank from Athens or
Eleusis, whether it was the avenging Furies or the pure goddess of
the mysteries before whom he trembled to appear. Give but freedom
to the people, they said, to declare what they really think, and who
so base as to hesitate between Seneca and Nero—Nero, who more
than once deserved the sack, the serpent, and the ape, the
instruments of death for parricide. True, Orestes by divine command
had slain his mother; but he at least avenged the death of a father—
Nero had assisted at the slaughter of Claudius; Orestes spared at
least his wife and sister—Nero had murdered both; Orestes had not
poisoned a kinsman—Nero had mingled aconite for many: above all,
Orestes had never sung upon the stage, nor chanted, like Nero, the
fall of Ilium. This it seems was the crown and climax of his crimes,
the last and worst of the indignities he heaped on Rome; this was
the deed for which the sword of the avenger was most fitly drawn.
“For such,” exclaims Juvenal, “forsooth, were the acts, such were the
arts of our high-born prince, proud to degrade himself on a foreign
stage, and earn the paltry chaplets of the Grecian games. Let him
lay before the image of Domitius the mantle of Thyestes, the mask
of Antigone or Melanippe; let him hang his votive lyre on the marble
statue of Augustus.”
Beneath this veil of rhetoric lies a truth which it is the province of
history to remark. The Romans, from age to age, viewed their own
times in a very different light from that in which they have appeared
to posterity. The notion of Juvenal that the acting and singing of
Nero were in fact his most flagrant enormities was felt no doubt,
even in his own day, as a wild exaggeration; nevertheless it points to
the principle, then still in vigour, of the practical religion of antiquity,
the principle of faith in its social traditions. With cruelty and
oppression the Romans were so familiar that Nero’s atrocities in this
respect, so harrowing to our feelings, made little impression upon
them; but his desecration of their national manners, his
abandonment of the mos majorum, the usage of his ancestors,
startled them like impiety or sacrilege. They were not aware how far
they had really drifted from the habits of antiquity, how much of
foreign poison they had admitted into their veins. Theoretically they
still held in sanctimonious horror the customs of the stranger;
foreign usages might be innocent, nay, laudable, in their own place,
but to introduce them into Rome was a monstrous sin, a sin, not
against the gods in whom they no longer believed, but against the
nation, in which they believed more intensely perhaps than ever. The
state or nation was itself gradually assuming in their eyes the
personality of a distinct divinity, in which all other divinities were
absorbed; the Hellenism which Nero vaunted was apostasy from the
goddess Roma.
The Greeks on the other hand would regard,
we may suppose, with more indulgence the
caprices of their imperial visitor; they were
accustomed to flatter, and in this instance there
was some excuse for flattering a humour so
flattering to themselves. The miserable vices he
paraded before them were too like their own, at
least in their period of corruption, to elicit strong
moral reprobation. Nevertheless, if we may credit
our accounts, he found more effectual means of
disgusting them. The imperial tyranny was always
pursued, as by its shadow, by profuse and fatal
expenditure. It seemed unable to move without
Roman Bronze Kettle the attendance of a crowd of harpies, ever
demanding their prey with maw insatiable. Every
day required fresh plunder; every day
proscriptions and confiscations revealed the prince’s necessities, and
if these for a moment slackened for want of victims, his hands were
laid on the monuments of art, on every object on which money
could be raised throughout the devoted land. The temples as well as
the dwellings and the forums of Greece were ransacked again for
the costliest and most cherished treasures, to be sold by auction to
the highest bidder, or redeemed at exorbitant prices by their
unhappy owners. Greece was powerless to resist, and her murmurs
were drowned in the acclamations of the hired applauders; but she
felt her wrongs deeply, and the pretended boon of freedom,
accompanied by a precarious immunity, was regarded perhaps as an
insult rather than a favour.
Rome at least, it might be hoped, would breathe again during the
absence of her hateful tormentor. But this, we are assured, was as
far from her as ever. Her condition had become even more
miserable. The emperor had given the government of Italy to a
freedman named Helius, and this minion exercised cruelty and
rapine at his own caprice, not even deigning to ask the prince’s
pleasure beforehand on the executions and confiscations he
commanded. Yet Helius was not unfaithful to his master’s interests.
On the first symptoms of danger from discontent in the city or the
provinces, for such symptoms began at last to threaten, he urged
him to hasten back to the seat of government, and it was Nero’s
obstinacy alone that postponed his return for some months. “You
admonish me, you entreat me,” replied the infatuated wretch, “to
present myself again at Rome; nay, but you should rather dissuade
me from returning, until I have reaped my full harvest of laurels.”
This harvest was not yet gathered in, and the cries of the keeper of
the city, already trembling for the fate of the empire, were
disregarded, while there yet remained a stadium to be trodden, or a
chaplet to be won, in Greece. At the commencement, however, of
the year 68 the aspect of affairs had become still more serious. Plots
for the subversion of the government were believed to be rife in the
armies of the West. The heads of administration at Rome knew not
whom of their officers in Gaul or Spain to trust. Deep gloom had
settled down on the upper classes in the capital; the temper of the
populace itself, so long the stay of Nero’s tyranny, was uncertain.
Helius again urged him to hasten his return. He crossed over to
Greece to confer with him in person. He repeated his instances with
increasing fervour. At last, when there seemed no more of fame or
booty to be wrung from Greece, Nero deigned to take ship, though
the season of navigation had not yet commenced, and urged his
prow through stormy seas to the haven of Puteoli.
But Galba had become alarmed for his own safety. He had
received communications from a rebel, all whose acts were well
known to the government. He had been urged to proclaim himself
emperor, and no refusal on his part could efface the crime of having
been judged worthy of such a distinction. Indeed, so at least he
pretended, he had already intercepted orders from Nero to take his
life, and a plot for his assassination was opportunely detected
among a company of slaves presented him by a freedman of the
emperor. Thus impelled to provide for his own safety, he called his
troops together, and setting before them the images of the tyrant’s
noblest victims, harangued them on the state of public affairs. The
soldiers saluted him as imperator, but he would only allow himself to
be styled Legatus of the senate and the people. He proceeded,
however, at once to prorogue all civil business, and provide for
immediate war by raising forces, both legionary and auxiliary, from
the youth of the province. At the same time he convened the
notables of the country, to give perhaps a civil colour to his military
enterprise. The Gallic and Germanic legions, now reunited, after the
death of Vindex, had offered to raise Virginius to the purple; they
conjured him to assume the title of imperator, and inscribed on his
busts the names of Cæsar and Augustus. But he steadily refused the
honours thrust upon him, erased the obnoxious letters, and at length
persuaded his admirers to leave the decision of affairs to the
authorities at home. He entered, however, into communication with
Galba, who had now, it seems, determined on the attempt, and the
news was bruited far and wide that Gaul and Spain had revolted,
and that the empire had passed irrevocably from the monster Nero.
At once it appeared how many pretenders to power might exist in
the bosom of the provincial camps. The fatal secret of the empire,
that a prince might be created elsewhere than at Rome, so long
undiscovered, so alien, as was supposed, from the sentiments of the
age, was revealed in more than one quarter. Not in Gaul and Spain
only, but in Africa and lower Germany, the legions were ready to
make an emperor of their own chief. Clodius Macer in the one,
Fonteius Capito in the other, were proclaimed by the soldiers. At the
same time Salvius Otho, Nero’s ancient favourite, who was weary of
his long oblivion on the shores of the Atlantic, declared himself a
supporter of Galba, and lent him his own slaves and plate, to swell
his retinue and increase his resources. The civil wars had again
begun.
Such was the march of disaffection, the first
anticipations of which had been revealed to
Helius before the end of 66, and had induced him
to urge the emperor, first by letter and afterwards
in person, to hasten home. Nero, as we have
seen, could not be persuaded to regard them
seriously, or postpone to their consideration his
paltry gratifications and amusements. After his
return to Rome he had again quitted it for Naples
in March, 68, and it was on the 19th of that
month, the anniversary of Agrippina’s murder,
while presiding at a gymnastic exhibition, that he
received the news of the revolt of Vindex. Still he
treated the announcement with contempt, and
even expressed satisfaction at the prospect of
new confiscations. He witnessed the contests
with unabated interest, and retired from them to
a banquet. Interrupted by fresh and more
alarming despatches, he resented them with
petulant ill-humour; for eight days he would
neither issue orders nor be spoken to on the
subject. Finally arrived a manifesto from Vindex
himself, which moved him to send a message to
the senate, requiring it to denounce the rebel as Roman Method of
a public enemy; but he excused himself from Attack from above
appearing in person, alleging a cold or sore
throat, which he must nurse for the conservation
of his voice. Nothing so much incensed him as Vindex calling him
Ahenobarbus instead of Nero, and disparaging his skill in singing.
“Had they ever heard a better performer?” he asked peevishly of all
around him. He now hurried trembling to Rome; but he was
reassured, we are told, on the way by noticing a sculpture which
represented a Gallic soldier dragged headlong by a Roman knight.
Accordingly, with his usual levity, instead of consulting in full senate,
or haranguing on the state of affairs in the Forum, he held a hasty
conversation with a few only of his nobles, and passed the day in
explaining to them a new water-organ, on which he proposed, he
said, “with Vindex’s good leave,” to perform in public. He completed
and dedicated a temple to Poppæa: once more he celebrated the
games of the circus, once more he played and sang, and drove the
chariot. But it was for the last time. Vindex had fallen, but Galba, it
was now announced, had raised the standard of revolt. The rebel’s
property in Rome was immediately confiscated, to which he replied
by selling under the spear the emperor’s estates in Spain. The hour
of retribution, long delayed, was now swiftly advancing; courier after
courier was dashing through the gates, bringing news of the
defection of generals and legions. The revolt of Virginius was no
longer doubtful. At this intelligence the puny tyrant fainted; coming
to himself he tore his robes and smote his head, with pusillanimous
wailings. To the consolations of his nurse he replied, with the cries of
an infant, “never was such ill-fortune as his; other Cæsars had fallen
by the sword, he alone must lose the empire still living.” At last he
recollected himself sufficiently to summon troops from Illyricum for
the defence of Italy; but these, it was found, were in
correspondence with the enemy. Another resource, which served
only to show to what straits he was driven, was to land sailors from
the fleet at Ostia, and form them into a legion. Then he invoked the
pampered populace to arise in his behalf, and dressed up courtesans
and dancers as Amazons to attend his march; next moment he
exclaimed that he would take ship for Alexandria, and there earn
subsistence by singing in the streets. Again he launched into
invectives against the magistrates abroad, threatening to recall and
disgrace them throughout his dominions; the provinces he would
give up to pillage, he would slay every Gaul in the city, he would
massacre the senate, he would let loose the lions on the populace,
he would lay Rome in ashes. Finally, the tyrant’s vein exhausted, he
proposed in woman’s mood to meet the rebels unarmed, trusting in
his beauty, his tears, and the persuasive tones of his voice, to win
them to obedience.
Meanwhile the excitement among the knights and senators at the
prospect of deliverance kept pace with the progress of revolt abroad.
Portents were occurring at their doors.
Blood rained on the Alban Mount; the gates
of the Julian sepulchre burst open of their
own accord. The Hundred Days of Nero
were drawing rapidly to a close. He had
landed in Italy about the end of February,
and now at the beginning of June his cause
had already become hopeless. Galba,
though steadfast in his resolution, had not
yet set his troops in motion; nevertheless,
Nero was no longer safe in the city. The
people, at first indifferent, were now
clamouring against him; for there was a
dearth of provisions, and a vessel, just
arrived from Alexandria, was found, to their
disgust, to bear not grain, but fine sand for
the wrestlers in the amphitheatre. The
prætorians had been seduced by their
prefect Nymphidius, to whom the camp was
A Centurion Officer abandoned by the flight of Tigellinus. Nero
was left without advisers; the senators
stood aloof; of Helius, lately so powerful
and energetic, we hear nothing. Terrified by dreams, stung by
ridicule or desertion, when his last hope of succour was announced
to have deceived him the wretched tyrant started from his couch at
supper, upset the tables, and dashed his choicest vessels to the
ground; then taking poison from Locusta and placing it in a golden
casket, he crossed from the palace to the Servilian gardens, and
sent his trustiest freedmen to secure a galley at Ostia. He conjured
some tribunes and centurions, with a handful of guards, to join his
flight; but all refused, and one blunter than the rest exclaimed
tauntingly, “Is it then so hard to die?”
FOOTNOTES
[18] [Apologists are not wanting who assert that it was chiefly
Nero’s contempt for Roman customs which alienated the
“respectable citizens”; that these citizens were really more brutal
than Nero; and that the emperor’s chief fault was criminal
indulgence towards his courtiers, rather than cruelty. Such views
illustrate the curious oscillations of historical criticism, to which we
have so often had occasion to refer. Even the most sympathetic
and flattering view of Nero presents him as at least reflecting the
conditions of a society in some respects monstrous.]
Otho, who had gone to Rome with Galba, seized the opportunity
of Galba’s mistake to place himself on the throne. He had long
solicited the favour of the soldiers and people, had given away entire
estates to individuals, had, when Galba dined with him, given money
to the emperor’s escort, and Galba had overlooked all this, because
one of his favourites, Vinius, whose daughter Otho wished to marry,
had come to a secret understanding with the latter. Otho instituted a
formal conspiracy, corrupted the soldiers by gifts and promises, and
had himself proclaimed emperor in a camp of the prætorians, a few
days after Piso’s appointment. He left the camp at the head of the
soldiers who had chosen him, entered the town, killed Galba and his
co-regent, and was acknowledged emperor by the people and
senate. This took place on the 15th of January of the year 69, when
Galba had only reigned seven months and a few days.
The new emperor only maintained his rule for three months. All
the provinces and armies swore allegiance to him after Galba’s
death, only the legions of the Rhine and Upper Germany denied him
obedience. They had already rebelled against Galba, and proclaimed
the leader of the troops on the lower Rhine, Aulus Vitellius, emperor,
as they had not been recompensed by Galba for the support they
had given him against Nero. This rival, although other legions
declared for him, would not in himself have been dangerous to Otho,
as he had become so enervated by self-indulgence that he was
wanting in activity and energy as well as in decision; but in Fabius
Valens and Aulus Cæcina, he possessed two able generals, who
placed themselves at the head of the legions in his stead.
With the rebellious troops they crossed the Alps into upper Italy
and fell upon Otho, who had hastily collected as many soldiers as
possible and led them against the enemy. At first the generals of
Vitellius were the losers in a few small engagements, as mutual
jealousy induced them to act separately, but as soon as they
concentrated themselves they were far superior to their adversaries.
Otho ought, therefore, to have done everything to delay the crisis
until the reinforcements which he was expecting from the provinces
of the Danube had arrived. He nevertheless did the reverse, and
throughout the entire war showed himself a worthy comrade of
Nero.
He had been the husband of the notorious Poppæa Sabina; had
formerly participated with his imperial friend in all kinds of pleasures,
and had indulged in so much dissipation that he had not only fallen
deeply into debt, but had also become enervated and incapable of
any exertion. This had already become apparent in the rebellion
against Galba; for he had lost all courage at the moment of action,
and would have given the whole thing up had not his fellow-
conspirators compelled him to persist in his designs. Besides he was
no general. His troops, which for the greater part consisted of
prætorians and soldiers of Nero, clung to him with devotion, and
were eager to fight, but they did not trust their officers and would
no longer take orders from them. This determined him to bring the
fight to a speedy end, as he felt that at any moment he might be
deserted by his own people. In spite of this, as he had not been
present in the earlier smaller fights, so now he took no personal
share in the great battle which was to decide his own fate.
In the vicinity of Cremona, Cæcina and Valens fell on Otho’s army.
It was beaten, suffered considerable loss, and then the greater part
went over to the enemy. Otho’s cause was, nevertheless, by no
means lost; for the prætorians adhered steadfastly to him, the
legions of the provinces of the Danube were already on the march,
and the entire East as well as Africa was open to him. Only he was
too indolent and effeminate to be able to face continuous exertions
and hardships, and from the example of his beaten army he saw
how ephemeral the devotion of his soldiers had been. So he lost
courage, and decided, in spite of the remonstrances and requests of
his friends, to put an end to his life. He stabbed himself to the heart
with a firmness rarely found in a voluptuary, and by this action won
for himself the reputation with posterity of having purchased the
peace of his country with his own life.
Historians have therefore praised him above his deserts, and
placed words in his mouth which stand in opposition to his life and
principles. For instance, he is reported to have said to his friends and
relatives who wished to restrain him from suicide: “Others have
gained fame by governing well; my fame, on the contrary, is to
consist in my giving up the government of the empire, rather than
ruin it by my ambition.” Those who recall the fact that Otho
throughout his life lived and acted according to the maxims of a
Nero, will know how to divest this story of all that gives his death
the appearance of a grand and noble act; for although it cannot be
denied that Otho thereby put an end to the civil war, and died in
peace and quietness, nevertheless he was not guided by courage or
love of country, but by indolence and despair.
How little the sacrifice of his life cost a Roman at this period, and
why Otho’s death must be regarded in quite another light from that
in which a similar deed would be looked upon nowadays, is apparent
from the fact that some of his soldiers killed themselves at his
funeral pile, not from fear of the future, but that they might follow
the glorious example of their leader.
After Otho’s death, the Roman senate not only recognised Vitellius
as emperor, but determined publicly to thank the Germanic army for
having appointed him. Whilst his generals were fighting for his
dominion, Vitellius remained in Gaul, and after the victory made no
haste to take possession of the empire; he first enjoyed a period of
repose at Lyons, and then stopped at Cremona and Bologna to hold
revels and to see the gladiatorial displays. It was only in July (69),
three months after Otho’s death, that he entered Rome.
With his accession, all
the crimes and
prodigalities of the
government of a Caligula,
a Claudius, and a Nero
were repeated, although
he was wanting neither in
culture nor in better
qualities. He had only
attained to consideration
by his vices, and won over
the soldiers in Germany by
his familiar bearing. A dull,
slack, and withal cruel
disposition, a greediness
which amounted to
A Roman Slinger voraciousness, and a
prodigality in which he
even surpassed Nero, were
the soul of his existence and government. Only thinking of pleasure
and idle repose, even on the march to Rome, he allowed his army to
rob and plunder at will, and permitted all kinds of excesses and
insubordination. In Rome, freedmen, comedians, and revellers were
his most cherished companions, and he who knew how to prepare
the most voluptuous feast, rose in his favour.
In order to obtain money for his prodigalities, like Caligula and
Nero, he committed all sorts of inhuman cruelties. For example: he
freed himself from debt by having his creditors killed, and when one
of them, condemned to death, sought to obtain favour by making
the emperor a legacy, but unfortunately gave him a co-heir, Vitellius
had the latter as well as the former put out of the way, and took the
wealth of both. His revelries and prodigalities surpassed all
realisation.
By the use of emetics he was enabled to take daily from three to
four principal meals. Once, for untold gold, he had marvellous dishes
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookball.com