MATLAB | R2024b更新了哪些好玩的东西?

Hey, 又到了一年两度的MATLAB更新时刻,MATLAB R2024b正式版发布啦!,直接来看看有哪些我认为比较有意思的更新吧!

1 小提琴图

天塌了,我这两天才写了个半小提琴图咋画,MATLAB 官方就出了小提琴图绘制方法。

小提琴图基础画法

matlab 复制代码
ydata = randn(100,3);
violinplot(ydata)

分组数据绘制小提琴图

比如100个数据,前20个分到第一组,中间50个分到第二组,最后30个分到第三组

matlab 复制代码
ydata = randn(100, 1);
xgroupdata = categorical(repelem(["group1";"group2";"group3"], [20,50,30]));
violinplot(xgroupdata, ydata)

对比小提琴图

matlab 复制代码
ydata1 = randn(100,1);
ydata2 = randn(100,1)+5;

xgroupdata1 = categorical(repelem(["group1";"group2"],[90,10]));
xgroupdata2 = categorical(repelem(["group3";"group4"],[25,75]));

tbl = table(xgroupdata1,xgroupdata2, ...
    ydata1,ydata2,VariableNames=["X1","X2","Y1","Y2"]);
matlab 复制代码
figure
violinplot(tbl,"X1","Y1")

一组数据一种分类方式:

matlab 复制代码
figure
violinplot(tbl,"X1",["Y1","Y2"])

两组数据(橘色一组蓝色一组)同一种分类方式:

matlab 复制代码
figure
violinplot(tbl,["X1","X2"],"Y1")

一组数据两种(橘色一种蓝色一种)分类方式:

matlab 复制代码
figure
violinplot(tbl,["X1","X2"],["Y1","Y2"])

两组数据两种分类方式:

位置和颜色分组数据

matlab 复制代码
ydata = randn(100,1);

xgroupdata = categorical(repelem(["group1";"group2";"group3"], [20;50;30]));
cgroupdata = categorical(repelem(["a";"b";"a";"b";"c";"d";"e"], [10;10;25;25;10;10;10]));

violinplot(xgroupdata, ydata, GroupByColor = cgroupdata)

半小提琴图

左右版本:

matlab 复制代码
ydata1 = randn(100,1);
ydata2 = [randn(25,1)+2; randn(75,1)+5];

xgroupdata1 = repelem([1;2], [50;50]);
xgroupdata2 = repelem([1;2], [25;75]);

violinplot(xgroupdata1, ydata1, DensityDirection = "positive")
hold on
violinplot(xgroupdata2, ydata2, DensityDirection = "negative")
legend("ydata1","ydata2")

上下版本:

matlab 复制代码
violinplot(xgroupdata1,ydata1,Orientation="horizontal",DensityDirection="positive")
hold on
violinplot(xgroupdata2,ydata2,Orientation="horizontal",DensityDirection="negative")
legend("ydata1","ydata2")

2 新版罗盘图

估计老版本compass函数会在未来被删掉,新出的罗盘图函数叫compassplot:

matlab 复制代码
rho = [1 3 2 2];
theta = [0 pi/4 3*pi/4 5*pi/4];
compassplot(theta,rho)
matlab 复制代码
[a,b] = meshgrid(-2:2);
Z = a + b*1i;
compassplot(Z)

3 无限延伸的平面

constantplane函数,这个用来画示意图还是非常有用的:

matlab 复制代码
XYZ = rand([500,3]);
B= XYZ(:,1) < .5;
hold on
scatter3(XYZ(B, 1), XYZ(B, 2), XYZ(B, 3), 15, 'filled')
scatter3(XYZ(~B, 1), XYZ(~B, 2), XYZ(~B, 3), 15, 'filled')

constantplane("x", .5 , FaceAlpha = 0.5);
view(3)

4 图标的宽度

使用图例的IconColumnWidth属性可以控制图标的宽度

matlab 复制代码
x = [1 3 4 3 1 0];
y = [0 0 2 4 4 2];
hold on
fill(x,y,'cyan','FaceAlpha',0.3)
fill(x+2,y,'magenta','FaceAlpha',0.3)
fill(x+1,y+2,'yellow','FaceAlpha',0.3)
   
lgdHdl = legend();
lgdHdl.IconColumnWidth = 5;

5 饼图和甜甜圈图引入other项

matlab 复制代码
cats = categorical([ "Glazed"  "Jelly"  "Jelly"  "Jelly" , ... 
     "Sugar" , "Sugar" , "Plain" , "" , "" , "" , "" ,]);
 donutchart (cats,LabelStyle= "name" )

以前未定义项目不会显示,现在会显示为other:

可通过以下方式关闭:

matlab 复制代码
donutchart(cats,LabelStyle="name",ShowOthers="off")

6 柱状图标签

标签终于彻底变成柱状图一部分:

matlab 复制代码
x = [1 2 3];
vals = [2 3 6; 11 23 26; 2 4 23];
b = bar(x,vals);
b(1).Labels = b(1).YData;
b(2).Labels = b(2).YData;
b(3).Labels = b(3).YData;
matlab 复制代码
b(1).LabelLocation = "end-inside";
b(2).LabelLocation = "end-inside";
b(3).LabelLocation = "end-inside";

7 更方便构建跨多个网格单元UI组件


8 MATLAB测试版新桌面

可以测试包括深色主题、更新的布局和扩展的搜索功能,去以下fileexchange链接下载:


9 实时编辑器范围滑块


10 实时编辑器修改代码字体


11 找出在范围内的数据

matlab 复制代码
A = [1 3 5 7 9];
TF = isbetween(A,2,7)
% TF = 1x5 logical array
%  0   1   1   1   0
val = A(TF)
% val = 1×3
%     3     5     7

以前则需要:

matlab 复制代码
TF = A >= 2 & A <= 7

12 去除NaN值和异常值

matlab 复制代码
A = [1 3 NaN 6 NaN];
R = rmmissing(A)
% R = 1×3
%     1     3     6

以前则需要

matlab 复制代码
R = A(~isnan(A))

异常值可以使用rmoutliers函数去除。

13 检测数据是否近似

直接问数据相等与否会因为有误差给出否的结果,现在可以问数据是否相似:

matlab 复制代码
A = sin(3/4*pi);
B = 1/sqrt(2);
A==B
% ans = logical
%  0
isapprox(A,B)
% ans = logical
%  1

后言

篇幅问题很多更新不再赘述,其中包括帮助函数help返回的信息格式会更加统一,还有一个对初学者很友好的更新,就是报错的具体位置会用^这个符号进行标注,大概这样:

然后简单叙述一下关于文件处理的部分此外比如可以使用unzip解压有密码的压缩包,可以使用readdictionarywritedictionary读取json文件,python和MATLAB字典可以互相使用:

此外在工具箱方面主要有以下更新

  • 5G Toolbox - 探索候选 6G 波形生成
  • DSP HDL Toolbox - 使用交互式 DSP HDL IP Designer 应用程序定制、配置 DSP 算法并生成 HDL 代码和验证组件
  • Simulink Control Design - 设计和实施非线性和数据驱动的控制技术,例如滑动模式和迭代学习控制
  • System Composer - 编辑子集视图;使用活动和序列图描述系统行为

更多详细信息请见:


相关推荐
jiao0000123 分钟前
数据结构——队列
c语言·数据结构·算法
kaneki_lh27 分钟前
数据结构 - 栈
数据结构
铁匠匠匠27 分钟前
从零开始学数据结构系列之第六章《排序简介》
c语言·数据结构·经验分享·笔记·学习·开源·课程设计
C-SDN花园GGbond29 分钟前
【探索数据结构与算法】插入排序:原理、实现与分析(图文详解)
c语言·开发语言·数据结构·排序算法
架构文摘JGWZ2 小时前
Java 23 的12 个新特性!!
java·开发语言·学习
2401_858120532 小时前
深入理解MATLAB中的事件处理机制
前端·javascript·matlab
leon6252 小时前
优化算法(一)—遗传算法(Genetic Algorithm)附MATLAB程序
开发语言·算法·matlab
CV工程师小林2 小时前
【算法】BFS 系列之边权为 1 的最短路问题
数据结构·c++·算法·leetcode·宽度优先
小齿轮lsl2 小时前
PFC理论基础与Matlab仿真模型学习笔记(1)--PFC电路概述
笔记·学习·matlab
Navigator_Z2 小时前
数据结构C //线性表(链表)ADT结构及相关函数
c语言·数据结构·算法·链表