当前位置:网站首页>MATLAB初次学习
MATLAB初次学习
2022-07-15 15:11:00 【W_oilpicture】
前言
人生如逆旅,我亦是行人。
一、MATLAB 变量命名规则
- 变量名区分大小写;
- 变量名长度不超过 63 位;
- 变量名以字母开头,可以由字母、数字和下划线组成,但不能使用标点;
- 变量名简洁明了,通过变量名可以直观看出变量所表示的物理意义;
二、MATLAB 数据类型
- 数字
- 字符与字符串
s = 'a'
abs(s) //执行 ASCII 码,ans = 97
char(65) //表示:ans = A
num2str(65) //ans = 65
str = 'I Love MATLAB & Machine Learning.'
length(str) //ans = 33,空格也算长度
- 矩阵
A = [1 2 3; 4 5 2; 3 2 7] //定义一个矩阵
B = A' //求矩阵 A 的转置矩阵
C = A(:) //将矩阵 A 竖着拉伸
D = inv(A) //求矩阵 A 的逆矩阵
A * D //原矩阵乘以逆矩阵,为单位矩阵
E = zeros(10,5,3) //生成三个10行5列,元素全为0的三维矩阵
问:rand、randi 和 randn 的区别:
1、rand 生成均匀分布的伪随机数,分布在(0 ~ 1)之间
- 主要语法:rand(m,n) 生成 m 行 n 列的均匀分布的伪随机数;rand(m,n,‘double’) 生成指定精度的均匀分布的伪随机数,参数还可以 ‘single’,rand(RandStream,m,n)利用制定的 RandStream(随机数种子)生成伪随机数;
2、randn 生成标准正态分布的伪随机数(均值为 0 ,方差为 1)
- 主要语法:同上
3、randi 生成均匀分布的伪随机数
- 主要语法:randi(iMax) 在开区间(0,iMax)生成均匀分布的伪随机数; randi(iMax,m,n) 在开区间(0,iMax)生成 mXn 型随机矩阵;r = randi([iMin,iMax],m,n) 在开区间(iMin,iMAX)生成 mXn 型随机矩阵。
- 元胞数组
A = cell(1,6)%a=b=666
A{
2} = eye(3)%从1开始,python 从0开始,索引
A{
5} = magic(5)
B = A{
5}

- 结构体
% 5.结构体
books = struct('name',{
{
'Machine Learning','Data Mining'}},'price',[30,40])
books.name % 属性
books.name(1) % 小括号取出来的是 cell
books.name{
1} % 大括号取出来的是 字符串
1、清空环境变量及命令
- clear all :清除 workspace 中的所有变量;
- clc :清除 command window 中的所有命令;
边栏推荐
- 聊一聊Spark实现TopN的几种方式
- Redis集群长时间连接不上问题Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join
- LeetCode_ Sliding window_ Simple_ 643. Maximum average number of subarrays I
- 网络安全网格概念以及特点简单普及
- ERROR 1366 (HY000): Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7‘ for column ‘s_name‘ at row 1
- 40 + times improvement, explain in detail how to optimize the performance of juicefs metadata backup and recovery
- Sending cluster meet messages to join the cluster waiting for the cluster to join
- 普歌—码上鸿鹄团队 winSCP和Xshell 基本配置用法
- In the fiery VR market of yuancosmos, bytes have just touched a little bit
- Experience first! What kind of experience is it to write fluent in the browser?
猜你喜欢

【详细教程】一文参透MongoDB聚合查询

【SpaceNet】SN6:Multi-Sensor All-Weather Mapping

普歌-码上鸿鹄团队-Vscode 代码格式化整理

The global cloud market is growing rapidly, and data security has entered a strong regulatory era of rule of law

树和二叉树

收银系统的硬件有哪些?

Start of u-boot S analysis (II)
![[flutter -- actual combat] Introduction to flutter](/img/01/c588f75313580063cf32cc01677600.jpg)
[flutter -- actual combat] Introduction to flutter

ASTM e595-15 (2021) outgassing latest standard for degassing test

Power change in dispute: a limited game for head players
随机推荐
普歌—码上鸿鹄团队 winSCP和Xshell 基本配置用法
u-boot之顶层Makefile分析(三)
SQL Server存储过程多角度介绍建议收藏
LeetCode_ Sliding window_ Simple_ 643. Maximum average number of subarrays I
Generate XML file of VOC dataset
抢先体验! 在浏览器里写 Flutter 是一种什么体验?
EN 1317-5 Road restraint system products - CE certification
【答疑解惑】 裁员浪潮中,N+1 到底指什么?
EN 1158建筑五金件门协调装置—CE认证
动作捕捉协助中国电力科学研究院建立边云协同电力自主巡检系统
Motion capture assists China Electric Power Research Institute in establishing a side cloud collaborative power independent inspection system
The distant savior obeys the objective law (III) -- cultural attribute
C#一个方法返回多个值建议收藏
LeNet
Three obstacles to the IPO of "adopt a cow"
剑指Offer16-数值的整数次方-位运算
eureka server剖析
聊一聊Spark实现TopN的几种方式
MySQL数据库忘记密码怎么办???
uboot环境搭建与编译