门户网站的特点点播视频网站怎么建设
系列文章目录
文章目录
- 系列文章目录
 - 前言
 - 1 基本用法
 - 总结
 - 基础语法
 - 桌面管理
 - 矩阵
 - 均匀间隔矢量
 - 矩阵创建
 - 矩阵索引
 
前言
介绍了matlab的基本用法
1 基本用法
>> save filename.mat  % 将当前工作区的所有变量保存为mat文件
>> load filename.mat  % 加载文件>> load filename variable  % 只加载filename.mat中的某一variable
>> save filename variable  % 只把某个variable变量保存在filename.mat中>> format long 
>> format short  % 切换在command中的显示精度
 
矩阵操作
h = [1 2 3]
v = [1;3;5]
c = [1 3 4; 1 3 5]
y = [1:10]  % 1 2 3 ... 10
z = 1:0.5:5  % 1 1.5 2 2.5 ... 5
b = 1:5:10   % 1 6
b = linspace(0,1,5)  % 从 [0,1]共5个数
b = b'  % 转置
rand(x)  % x * x 随即矩阵
rand(x, y) % x row y col
ones(x, y)
zeros(x, y)
size(var)  % row, col
 
矩阵取值
matrix(row, col) % 矩阵第row行,col列
density = data(:,2);  % 所有第二列
volumes = data(:, 3:4)  % 所有第3 ~ 4列
volumes = data(:, 2:end)
density([1 3 4])  % 取第1 3 6个元素
 
矩阵运算
.*  % 点乘,对应元素相乘
 
[dr dc] = size(data)
[vMax, idx] = max(v2)
 
帮助文档
doc randi
 
plot
plot(sample, mass1)
hold on
plot(smaple, mass2, "r--*")
hold offplot(sample,mass1,"ks")
hold on
plot(sample,mass2,"r*")
hold off
title("Sample Mass")
ylabel("Mass (g)")
legend("Exp A", "Exp B")
 
文件操作
 蓝色代表要导入的数据, 黄色代表缺失(NaN == Not a Number)
 excel
excel.tablehead
 
logic
z = v1(v1<4)
v1(v1<4) = 0
&  and
|  or
 
控制语句
if doPlot == 1plot(density)title("Sample Densities")xticklabels(element)ylabel("Density (g/cm^3)")
elsedisp("The density of " + element ...+ " is " + density)
endfor idx = 1:length(density)hold onplot(idx,density(idx),"*")hold offpause(0.2)
end
 
总结
基础语法
| x = pi | 创建变量并赋值π\piπ | 
| y = sin(-5) | 函数调用 | 
桌面管理
| 功能 | eg | description | 
|---|---|---|
| save | save data.mat | 将当前工作区的内容保存为MAT文件 | 
| load | load data.mat | 从MAT文件中加载变量到工作区 | 
| clear | ||
| clc | ||
| format | format long format short  | 更改显示模式 | 
矩阵
| 3 | 标量 | 
| [3 5] | 行向量 | 
| [3; 5] | 列向量 | 
| [1 2 3; 1 2 3] | 矩阵 | 
均匀间隔矢量
| 1:4 | [1 2 3 4] | 
| 1:0.5:2 | [1 1.5 2] | 
| linspace(1,10, 5) | 5个元素,均匀的从[1,10] | 
矩阵创建
| rand(2) | 2*2方阵 | 
| zeros(2,3) | 2row 3col 0矩阵 | 
| ones(2,3) | 2row 3col 1矩阵 | 
矩阵索引
将其想象成函数调用
