MATLAB入门课程

Week 02

  1. format compact 命令可以出去 answer 中无用的 horizontal line
    format 有很多格式调整选择
  2. 我们可以将 command history 作为一栏拿出来,方便重输历史命令
  3. 通过 ... 我们可以将一个命令分行写
  4. plot()有option可以选,xlabel,ylabel,title,grid off
  5. axis([x-start,x-end,y-start,y-end])
    bar(x,y,z) 条状图
    figure 一个新的figure
    pie([p1,p2,p3...]) 饼图
    close(2) close figure 2
    close all close all figures

Week 03

command functionality
size() 返回 行数和列数
1:3:10 从3到10以3递增的数 等同于 colon(1,3,10)
如果开始数大于结尾数,就会导致 empty matrix 1行0列 [] 是0行0列
x(row, col) for indexing to retrieve or assign a value and when assigning, if x doesn't exist, a new matrix will be created
x(2,[1,3]) / x(1:2:4) subarray opeartions: return the value of x(2,1) and x(2,3)
end reserved keyword 能够表示matrix某一行/列的末尾
combing matrices 连接端必须有相同的行/列
G=H' Transpose of matrix
.* ./ .\ element-wise multiplication/ division/ division in reverse(Reciprocal)
矩阵运算 加减乘除必须满足行列要求 但如果有一个是scalar 那就没有这个限制

Week 04 Function IO

Command Functionality
x(:) 将所有矩阵转变为一个 n*1 的向量
sum() 计算矩阵每个列的和
function [a, b]=func(x, y) 函数的标准格式
global var 可以从 command line 以 global var 的形式访问全局变量
script 使用 script 的时候,变量会进入workspace

Week 05 Programmer's Toolbox

Command Functionality
max() 既可以返回每列最大数,还可以返回这个数的index
zeros() ones() diag() randn() randi() eye() diag() matrix building
fix() 取整
rng(n) rng('shuffle') 设置生成随机数的种子
input() fprintf() 输入输出
hold grid legend 图表的设置

Week 06 Selection

Commands Functionality
if ... elseif ... else ... end 选择语句
~= 不等于
& && 前者会计算左右两式,会将array中每个成员分别计算;后者只有在左式不确定情况下计算右式,而且只适用于 scalar value
nargin nargout 输入/输出参数的个数
%comment 如果在函数声明后面加注释,那么 help 命令就能像调用内置函数一样调用自定义函数
persistent 类似于C++的 local static variable
Robustness
function [table summa] = multable(n, m)
if nargin < 1
 error('must have at least one input argument');
end
if nargin < 2
 m = n;
elseif ~isscalar(m) || m < 1 || m ~= fix(m)
 error('m needs to be a positive integer');
end
if ~isscalar(n) || n < 1 || n ~= fix(n)
 error('n needs to be a positive integer');
end
table = (1:n)' * (1:m);
if nargout == 2

summa = sum(table(:));
end

Week 07 Loops

command functionality
15+3i 复数
v(logical(v)) 返回不是0的element,这就是 logical indexing
tick; func(), tok 计时
preallocation 提前创建满足要求的矩阵能有效减少计算时间

Week 08 Data Types

Command Functionality
class() whos() type / detailed info
double char logical data types
isa() type check
intmax('uint32') intmin realmax realmin range check
iint8() uint32() conversion
在string中''表示一个quote
sprintf() fprintf sprintf()需要一个output argument来接值 而 sprintf()不需要
struct field 只需要名称一样 不需要类型一样
rmfield() 不改变参数值,只返回改变值
cell 使用{}
cell() cell{} 前者得到指针(cell) double有[]包住 string虽然是一样 但是不能用==进行比较 后者得到内容
cell pointers 在matlab中,没有两个cell pointers能指向同一个object 所以在c++中我们可以通过传递指针改变函数外的值在matlab中行不通,因为我们不能在函数参数里面新建一个指针指向函数外的object,只能指向一个复制过后的object
String Functions
Struct Functions
Cell Functions

Week 09

Command Description
save + fileName + content in workspace load fileName
xslread() xslwrite()
~ tilde可以用来作为必要但我们不需要的output argument
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,196评论 0 10
  • 转自 http://www.kylen314.com/archives/412 不显示坐标刻度: set(gca,...
    天之道天知道阅读 6,428评论 0 2
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,230评论 0 13
  • 冯艺博日志|2018-06-16|星期六|晴天|懒人统治世界 一 昨天晚上睡觉之前,看到朋友圈大王会刘钊刘总推荐一...
    冯艺博阅读 2,622评论 0 0
  • 心学,是快乐生活的学问。 心学,超越古今,直指人心的学问。 心学,不是成功学,不是名利学,不是满足自己私欲的学问。...
    迅乔寒阅读 3,276评论 0 0

友情链接更多精彩内容