[MITOPENCOURSEWARE] 6.094 Introduction to Programming in MATLAB
Introduction to MATLAB
Lecture 1 Variables, Scripts, and Operations
Matlab Basic
- MATLAB can be thought of as a super-powerful graphing calculator
- In addition it is a programming language
一些命令
帮助命令
- help [ ]
- doc [ ] 更详细的帮助
注释
%
第一行注释为脚本的帮助文档
新建脚本
edit
edit [ ].m
输出字符串
disp
注意字符串使用单引号
保存变量到文件中
save
save myFile a b
- saves variables a and b to the file myfile.mat
- myfile.mat file is saved in the current directory
移除当前环境中变量
clear
加载文件中变量
load
清理命令窗口
clc
变量
- 创建和修改的变量会一直保存在工作区
- Matlab is a weekly typed language. 不需要初始化变量
- 变量命名:首位必须是字母;以字母、数字、下划线_ 组成
- 大小写敏感
- Built-in variables. Don’t use these names!
i
andj
can be used to indicate complex numberspi
has the value 3.1415926…ans
stores the last unassigned value (like on a calculator)Inf
and-Inf
are positive and negative infinityNaN
represents ‘Not a Number’
若不想显示输出,则在句末加上
;
数组[ ]
Two types of arrays
- matrix of numbers (either double or complex)
- cell array of objects (more advanced data structure)
- 行向量:在[ ] 中使用逗号或空格分隔值
- 列向量:在[ ]中使用
;
分隔 size( )
显示矩阵大小length( )
得到矩阵长度
- Initialize a vector of
ones
,zeros
, or random numbers
»o=ones(1,10)
row vector with 10 elements, all 1
»z=zeros(23,1)
column vector with 23 elements, all 0
»r=rand(1,45)
row vector with 45 elements (uniform [0,1])
»n=nan(1,69)
row vector of NaNs (useful for representing uninitialized variables)
- To initialize a linear vector of values use
linspace
»a=linspace(0,10,5)
starts at 0, ends at 10 (inclusive), 5 values
Can also use colon operator (:
)
»b=0:2:10
starts at 0, increments by 2, and ends at or before 10
increment can be decimal or negative
»c=1:5
if increment isn’t specified, default is 1 - To initialize logarithmically spaced values use
logspace
similar tolinspace
, but generate logarithmically spaced vectors - Vector Indexing
- Matlab 索引从0开始
- The index argument can be a vector
- 使用
max
和min
得到最大/小值和索引号 - 使用
find
特殊值或一定范围内的索引号 - To convert between subscripts and indices, use
ind2sub
, andsub2ind.
Homework 1
- 科学技术法使用
e
表示 - 虚数可以直接使用虚数单位i,j 表示也可以使用复数函数
complex( )
- 以e为底数,使用
exp( )
- 产生从a到b之间的随机数
r=a+(b-a)*rand(m,n)
- 数除矩阵要在除号前面加点
.
,平方也是 - 取平均值使用
mean
,可选择行或列
// 不保证没错
a = 10;
b = 2.5e23;
c = 2+3i;
d = exp((j*2*pi)/3);
aVec = [3.14 15 9 26];
bVec = [2.71;8;28;182];
cVec = 5:-0.2:-5;
dVec = logspace(0,1,100);
eVec = ['Hello'];
aMat = ones(9) * 2;
bMat = diag([1 2 3 4 5 4 3 2 1]);
cMat = reshape(1:100,[10 10]);
dMat = NaN(3,4);
eMat = [13 -1 5;-22 10 -87];
fMat = floor(rand(5,3)*6-3);
x = 1 / (1 + exp(-(a - 15)/6));
y = (sqrt(a) + b^(1/21))^pi;
z = log(real((c + d) * (c - d)) * sin(a * pi / 3))/(c * conj(c));
xVec = (1 / (sqrt(2 * pi * 2.5^2))) * exp(-power(cVec,2) / (2 * 2.5 * 2.5));
yVec = sqrt(power((aVec)',2) + power(bVec,2));
zVec = log10(1 ./ dVec);
xMat = (aVec * bVec) * aMat.^2;
yMat = bVec * aVec;
zMat = det(cMat) * (aMat * bMat)';
cSum = sum(cMat);
eMean = mean(eMat,2);
eMat = [1 1 1;eMat(2,:)];
cSub = cMat(2:9,2:9);
lin = 1:20;lin(2:2:20) = -lin(2:2:20);
r = rand(1,5);r(find(r<0.5)) = 0;
- 构造正余弦曲线使用函数
linspace
t = linspace(0,2*pi,100);
plot(t,sin(t));
hold on;
plot(t,cos(t),'r--');
xlabel('Time(x)');
ylabel('Function value');
title('Sin and Cos functions');
legend('Sin','Cos');
xlim([0 2*pi]);
ylim([-1.4 1.4]);
[MITOPENCOURSEWARE] 6.094 Introduction to Programming in MATLAB相关推荐
- Introduction to Programming I
Keyclack posters by Mohamed Chahin 获得更好的阅读体验请访问 Introduction to Programming I Acquire fundamental el ...
- [Introduction to programming in Java 笔记] 1.3.8 Gambler's ruin simulation 赌徒破产模拟
赌徒赢得机会有多大? public class Gambler {public static void main(String[] args){ // Run T experiments that s ...
- MATLAB工具箱,应用程序,软件和资源的精选清单
精选的MATLAB工具箱,应用程序,软件和资源的精选清单. # Awesome MATLAB [![Awesome](https://cdn.rawgit.com/sindresorhus/aweso ...
- 骨架提取matlab细化算法,基于拉普拉斯收缩的三维模型骨架提取算法及其Matlab实现...
3D skeleton extraction algorithm via Laplace contraction and its realization in Matlab JI Weijie 1 冀 ...
- 计算机编程课程顺序_您可以在6月开始参加630项免费的在线编程和计算机科学课程...
计算机编程课程顺序 Six years ago, universities like MIT and Stanford first opened up free online courses to t ...
- 计算机编程课程顺序_620多个免费的在线编程和计算机科学课程,您可以在三月开始
计算机编程课程顺序 Six years ago, universities like MIT and Stanford first opened up free online courses to t ...
- 计算机编程课程顺序_您可以在2月开始免费在线编程和计算机科学课程
计算机编程课程顺序 Seven years ago, universities like MIT and Stanford first opened up free online courses to ...
- 无责任共享 Coursera、Udacity 等课程视频
本文转载自网络,原作者不详. (本文是用 markdown 写的,访问 https://www.zybuluo.com/illuz/note/71868 获得更佳体验) 程序语言 interactiv ...
- 无责任共享 Coursera、Udacity 等课程视频【百度云】
(本文是用 markdown 写的,访问 https://www.zybuluo.com/illuz/note/71868 获得更佳体验) [百毒云群组] 这个帖子是我三年前发的,当时还是学生党收集了 ...
最新文章
- 《父亲家书》选:父亲的忙碌和欣喜
- 拥抱开放计算标准 重构数据中心格局
- elasticsearch 通过curl的操作
- Tech·Ed 2007大会课程内容
- Docker最全教程——从理论到实战(四)
- ubuntu 13.04 找回丢失的grub2
- 入口函数ufusr()的示例 3.2.2
- OEA中的缓存模块设计
- armstrong number in python_Python3 From Zero——{最初的意识:008~初级实例演练}
- dirent--文件以及文件夹相关操作(跨平台)
- Goland常用快捷键
- CGCS2000转WGS84
- 手机如何快速转换图片格式?改图片格式手机如何操作?
- 安装python时无法访问筛选器,如何使用Python筛选器功能(详解)
- conda使用清华镜像安装pytorch
- ftp服务器一直在转未响应,打开ftp服务器未响应
- python 逻辑回归 复杂抽样_逻辑回归(Logistic Regression) ----转载
- 人脸实名认证实现方案(微信H5百度云篇)
- 数据挖掘利器 selenium实战案例--论文数据挖掘与可视化分析(上)
- AUTOSAR开发工具DaVinci Configurator里的Modules
热门文章
- VS.NET 学习方法论 ——我的VS.NET学习之旅
- iPhone无限重启
- 澤雷隨 (易經大意 韓長庚)
- 【Java面试题1】
- 【精品】SpringBoot跨域请求 解决方案汇总
- 计算机网络实验smtp 邮件,smtp计算机网络实验报告.doc
- Qt中按钮图标的设置、按钮按下时浮动效果设置 以及 QT的EXE程序图标设置
- 我的世界java国际版怎么注册账号_我的世界国际服账号免费注册的3个办法
- 婴儿名字[连通分量之邻接矩阵与DFS]
- 最接近计算机硬件的系统软件是,最接近计算机硬件的系统软件是