matlab 中的基本绘图指令与字符串操作指令

news/2025/2/12 20:16:31/

字符串指令

  • 创建字符串
    • 使用单引号将字符序列括起来创建字符串
    • 使用单引号创建的字符串是一个字符数组,每个字符都被视为一个独立的元素
      • 可以通过索引访问每个字符
    • 使用双引号创建的字符串是一个字符串数组,整个字符串被视为一个元素
      • 无法通过索引访问单个字符

>> a = "Hello World!"a = "Hello World!">> b = 'Hello World!'b ='Hello World!'>> b(1)ans ='H'

  • 拼接字符串
    • strcat
      • 水平地连接成单个字符串
>> str = strcat('Hello', 'World!')str ='HelloWorld!'
    • strvcat
>> str = strvcat('Hello', 'Wrold!')str =2×6 char 数组'Hello ''Wrold!'
    • char
>> str = char('Hello', 'World!')str =2×6 char 数组'Hello ''World!'

  • 字符串长度
>> str = 'Hello World!'str ='Hello World!'>> length(str)ans =12

  • 子字符串提取

>> str(2:7)ans ='ello W'

  • 字符串比较

str1 = "Hello">> str2 = "Hello"str2 = "Hello">> str3 = "hello"str3 = "hello">> strcmp(str1, str2)ans =logical1>> strcmp(str1, str3)ans =logical0

  • 字符串查找
>> str = 'Hello James, Hello World!'str ='Hello James, Hello World!'>> str2 = 'James'str2 ='James'>> strfind(str, str2)ans =7

  • 字符串替换

str ='Hello James, Hello World!'>> str2 = 'James'str2 ='James'>> strfind(str, str2)ans =7>> str3 = 'Potter'str3 ='Potter'>> strrep(str, str2, str3)ans ='Hello Potter, Hello World!'

  • 字符串转换
    • str2num函数
      • 将字符数组或字符串转换为数值数组
>> str = '123456789'str ='123456789'>> num1 = str2num(str)num1 =123456789>> num1(1)ans =123456789
    • num2str函数
      • 将数值转换为字符串

>> num = 123456789num =123456789>> str = num2str(num)str ='123456789'>> str(1)ans ='1'

Matlab绘图指令

  • 一维绘图
plot(x)

  • 二维绘图
plot(x, y)

  • 多次二维绘图
plot(x1, y1, x2, y2)

 


>> x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
>> y1 = [2, 3, 1, 4, 7, 3, 2, 1, 3];
>> x2 = [3, 4, 5, 6, 7, 8, 9, 10, 11 ];
>> y2 = [9, 3, 2, 3, 5, 6, 8, 2, 1];

 


  • 对数图绘制
semilogx(x1, y1)


semilogy(x1, y1)


loglog(x1, y1)


  • 极坐标
>> theta = linspace(0, 2*pi, 100);
>> rho = cos(theta).^2;
>> polar(theta, rho)

  • 直方图
>> randnum = rand(1000);
>> hist(randnum)



http://www.ppmy.cn/news/1186171.html

相关文章

人工智能-线性回归的从零开始实现

线性回归的从零开始实现 在了解线性回归的关键思想之后,我们可以开始通过代码来动手实现线性回归了。 在这一节中,我们将从零开始实现整个方法, 包括数据流水线、模型、损失函数和小批量随机梯度下降优化器。 虽然现代的深度学习框架几乎可以…

RemoveEmptyEntries

new char[] { | }, StringSplitOptions.RemoveEmptyEntries System.ArgumentException:DatagridViewComboBoxCell值无效

c# 自定义分表

背景 sqlserver 单表数据过多,数据量已经过亿,查询缓慢,之前是采取手动分表的处理,我是半路接手,现在想对其进行改造,但是项目比较老,无法使用现成的分表插件,我们分表是根据项目来&…

CentOS7安装playwright终极指南

CentOS7安装playwright终极指南 系统环境为CentOS Linux release 7.9.2009 (Core) 最小安装,考虑到playwright的安装需要 python3.7 ,本次直接选择安装python3.8。 升级libstdc cd /opt yum -y install wgetwget http://www.vuln.cn/wp-content/uploa…

人大与加拿大女王大学金融管理硕士项目:开启国际视野,成就金融领袖

生活中,我们总会遇到各种各样的困难和挑战。有时候,我们会感到沮丧、迷茫甚至绝望。但是,正是这些困难和挑战,让我们变得更加坚强、勇敢和成熟。在这个职场竞争愈发激烈的时代,不断地充实自己是非常重要的。如果你从事…

IPKISS 设计规则

如果想要使用 amf 中定义的层结构,那么需要导入 amf 包,虽然 amf 包可能不会被直接进行调用。导入的 amf 包永远需要被放在所有导入的第一行,否则运行时可能会报错。使用 ConnectBend 或者 ConnectManhattan 对器件结构进行连接时&#xff0c…

【tips】huggingface下载模型权重的方法

文章目录 方法1:直接在Huggingface上下载,但是要fanqiang,可以git clone或者在代码中: from huggingface_hub import snapshot_download # snapshot_download(repo_id"decapoda-research/llama-7b-hf") snapshot_downl…

【GEE】Google Earth Engine(GEE)注册详细教程无需教育邮箱

这个专栏真的是纠结了很久,不知道到底要不要分享自己在学习GEE的时候的一些经验和代码。因为本人在日常中使用Python和ENVI多点,虽然GEE也会用但不至于频繁使用,同时针对GEE其实官网给出了很多接口的使用方法,国内外也有很多人分享…