Ch01 - Introduction To MATLAB+Ch02 - MATLAB Basics (Part 1)
Ch01 - Introduction To MATLAB+Ch02 - MATLAB Basics (Part 1)
Ming Jiang
www.wcomms.com
课程介绍 (1/2)
教学目的及要求
• 主要介绍MATLAB编程语言的基本功能、特点及如何使用其来解决工程领域的
典型技术问题,如科学计算、算法仿真等
• 通过本课程的学习,学生应掌握如何编写实用、高效的MATLAB程序,了解使
用MATLAB解决工程与技术问题的方法,学习如何使用MATLAB的帮助系统查
询所需的目标函数等,从而提高逻辑思维与解决问题的能力
教学特色
• 在完成教材基本内容讲解的基础上,适当将电子专业基础理论课(如通信原理
等)的部分知识点以例子或习题的形式融入教学,让学生结合MATLAB编程进
行学习或复习
• 学生可同时在专业基础知识和MATLAB编程两个方面加深理解
• 通过布置适量的课后作业并适时安排一些简单的研究类课题,供学生进行理论
验证或实验研究,培养学生的创新思维与实际动手解决问题的能力
参考资料
• Stephen J. Chapman,《MATLAB编程》(第四版影印版),
科学出版社, 2011年4月, ISBN: 9787030305428
• Stephen J. Chapman, "MATLAB Programming for
Engineers" (4th Edition), Thomson Learning, Nov.
2007, ISBN: 9780495244493
• Amos Gilat, MATLAB: An Introduction with
Applications (4th Edition), John Wiley & Sons,2010年1
月,ISBN: 9780470767856
• 张威, MATLAB基础与编程入门 (第二版), 西安电子科技大学
出版社, 2008年1月, ISBN: 7560613306
• Brian R. Hunt, Ronald L. Lipsman, Jonathan M.
Rosenberg, "A Guide to MATLAB: for Beginners and
Experienced Users" (2nd Edition), Cambridge University
Press, Jun. 2006, ISBN: 9780521615655
Ming Jiang
www.wcomms.com
MATLAB Programming for Engineers
Chapter 1: Introduction to MATLAB
• What is MATLAB
• MATLAB runtime environment
Ming Jiang
The First Look
What is MATLAB ?
• MATrix LABoratory
• A computer program for engineering and scientific calculations
• Before: designed to perform matrix mathematics
• Now: a flexible computing system for solving any technical problem
What can MATLAB offer?
• MATLAB provides an incredibly rich variety of functions
• 1000+ basic functions -> much richer than other technical
programming languages
• Additional toolkits for different technical areas
What to learn?
• NOT possible to learn ALL MATLAB functions in this course
• Instead, students should:
• Understand how to write/debug/optimize MATLAB programs
• Get familiar with a subset of the most important functions
• Know how to search for the right function needed
Example:
x = A \ b
solve b = A*x in MATLAB
YES! Just as simple
as you see it!
Ming Jiang www.wcomms.com 10
Immediate Popularity!
• What is MATLAB
• MATLAB runtime environment
Ming Jiang
Installation Example: MATLAB 2019b (1/3)
MATLAB is FREE if you are a SYSUer!
https://software.sysu.edu.cn/matlab_dl
Command History
Window: displays
previous
commands
Workspace
Browser: shows
variables defined in
MATLAB Command Window:
workspace
Type your MATLAB commands here
Click here to
add the search
paths in your
OS
• Warning:
• Never use a variable with the same Example:
name as a MATLAB function or sin=5; sin(1)=?
command
• Never create an m-file with the same
name as a MATLAB function or
command Not
• Otherwise, that MATLAB function or intended
command will become inaccessible! result!
• Use the which command to find out the
version of the file, and where it is located
-> avoid misuse of name
Ming Jiang
www.wcomms.com
MATLAB Programming for Engineers
Chapter 2: MATLAB Basics (Part 1)
Ming Jiang
First Impression on MATLAB Programming
• Variable's name:
• MUST begin with a letter
• Then followed by any combination of letters,
numbers, and the underline ( _ ) character
var = 4i
var = 10 + 10i
Ming Jiang
Initialization of Variables
X = 1+3i;
Y = 2;
What if there is no
Var = X/2; semicolon?
Array = [1 2 3 4];
[1, 2, 3; 4, 5, 6]
2 x 3 array = matrix
[1 2 3
4 5 6]
[] Empty array = ?
[1 2 3; 4 5]
?
Ming Jiang www.wcomms.com 39
Initializing Variables in Assignment Statements (3/4)
>> Array=[1 2 3; 4 5]
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Notes:
• All rows have the same number of columns
• All columns have the same number of rows
>> x = 1:2.5:9
Smaller than 9
x =
>> a = zeros(2)
a = >> d = size(b); >> e = eye(3)
0 0
0 0 >> c = zeros(d) e =
Why call eye?
c =
>> b = zeros(2,3) 1 0 0
b = 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1
0 0 0
• 它是指用示波器在接收端观察到的一种图形
• 传输二进制信号波形时, 示波器上显示的图形很像
人的眼睛 ——故名“眼图”
Ming Jiang
Multi-dimensional Arrays (1/2)
% Array c: 2×3
c 2x3 48 double
% Array c: 2×3×2
c 2x3x2 96 double
% Array c: 2×3×2
>> c
c(:,:,1) =
>> a = [1 2 3; 4 5 6; 7 8 9; 10 11 12]
a =
1 2 3
The 5 th element
4 5 6 in memory
7 8 9
10 11 12
arr =
arr(1,:)
1 2 3 1 2 3
-4 -5 -6
7 8 9
3
arr(1:2:5) arr(:,3)
-6
9
1 7 -5
Not a recommended way:
easy confusion!
arr =
1 2 3 4
5 6 7 8
9 10 11 12
arr =
1 2 3 4
5 6 7 8
9 10 11 12
>> arr(1:2,1:3) = 1
arr =
1 1 1 4
1 1 1 8
9 10 11 12
Ming Jiang
Special Values (1/2)
>> pi = 10;
>> c = 2 * pi * 10
c =
200
Ming Jiang
Output Display Formats
Save x.dat to
>> x=[1.23 3.14 6.28; -5.1 7.00 0];
Examples >> save -ascii x.dat x
hard disk in
ASCII format
■ 本课程的课件
● 主要内容:本人制作
● 部分内容:参考了中山大学数据科学与计算机学院张雨浓教授
的2008年版课件
● 少量内容:参考了Kasetsart University的James Brucker博士
早期的课件
■ 下载地址:
http://www.wcomms.com/lectures/course-matlab.html
本课件及相关作业,仅限本课程教学使用
请勿上传互联网
谢谢合作!
WWW.WCOMMS.COM