wordpress 圖片鏈接下載成都seo整站
Hey, 又到了一年兩度的MATLAB更新時刻,MATLAB R2024b正式版發(fā)布啦!,直接來看看有哪些我認(rèn)為比較有意思的更新吧!
1 小提琴圖
天塌了,我這兩天才寫了個半小提琴圖咋畫,MATLAB 官方就出了小提琴圖繪制方法。
小提琴圖基礎(chǔ)畫法
ydata = randn(100,3);
violinplot(ydata)
分組數(shù)據(jù)繪制小提琴圖
比如100個數(shù)據(jù),前20個分到第一組,中間50個分到第二組,最后30個分到第三組
ydata = randn(100, 1);
xgroupdata = categorical(repelem(["group1";"group2";"group3"], [20,50,30]));
violinplot(xgroupdata, ydata)
對比小提琴圖
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"]);
figure
violinplot(tbl,"X1","Y1")
一組數(shù)據(jù)一種分類方式:
figure
violinplot(tbl,"X1",["Y1","Y2"])
兩組數(shù)據(jù)(橘色一組藍(lán)色一組)同一種分類方式:
figure
violinplot(tbl,["X1","X2"],"Y1")
一組數(shù)據(jù)兩種(橘色一種藍(lán)色一種)分類方式:
figure
violinplot(tbl,["X1","X2"],["Y1","Y2"])
兩組數(shù)據(jù)兩種分類方式:
位置和顏色分組數(shù)據(jù)
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)
半小提琴圖
左右版本:
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")
上下版本:
violinplot(xgroupdata1,ydata1,Orientation="horizontal",DensityDirection="positive")
hold on
violinplot(xgroupdata2,ydata2,Orientation="horizontal",DensityDirection="negative")
legend("ydata1","ydata2")
2 新版羅盤圖
估計老版本compass
函數(shù)會在未來被刪掉,新出的羅盤圖函數(shù)叫compassplot
:
rho = [1 3 2 2];
theta = [0 pi/4 3*pi/4 5*pi/4];
compassplot(theta,rho)
[a,b] = meshgrid(-2:2);
Z = a + b*1i;
compassplot(Z)
3 無限延伸的平面
constantplane
函數(shù),這個用來畫示意圖還是非常有用的:
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 圖標(biāo)的寬度
使用圖例的IconColumnWidth
屬性可以控制圖標(biāo)的寬度
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項
cats = categorical([ "Glazed" "Jelly" "Jelly" "Jelly" , ... "Sugar" , "Sugar" , "Plain" , "" , "" , "" , "" ,]);donutchart (cats,LabelStyle= "name" )
以前未定義項目不會顯示,現(xiàn)在會顯示為other:
可通過以下方式關(guān)閉:
donutchart(cats,LabelStyle="name",ShowOthers="off")
6 柱狀圖標(biāo)簽
標(biāo)簽終于徹底變成柱狀圖一部分:
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;
b(1).LabelLocation = "end-inside";
b(2).LabelLocation = "end-inside";
b(3).LabelLocation = "end-inside";
7 更方便構(gòu)建跨多個網(wǎng)格單元UI組件
8 MATLAB測試版新桌面
可以測試包括深色主題、更新的布局和擴(kuò)展的搜索功能,去以下fileexchange鏈接下載:
- https://www.mathworks.com/matlabcentral/fileexchange/119593-new-desktop-for-matlab-beta
9 實時編輯器范圍滑塊
10 實時編輯器修改代碼字體
11 找出在范圍內(nèi)的數(shù)據(jù)
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
以前則需要:
TF = A >= 2 & A <= 7
12 去除NaN值和異常值
A = [1 3 NaN 6 NaN];
R = rmmissing(A)
% R = 1×3
% 1 3 6
以前則需要
R = A(~isnan(A))
異常值可以使用rmoutliers
函數(shù)去除。
13 檢測數(shù)據(jù)是否近似
直接問數(shù)據(jù)相等與否會因為有誤差給出否的結(jié)果,現(xiàn)在可以問數(shù)據(jù)是否相似:
A = sin(3/4*pi);
B = 1/sqrt(2);
A==B
% ans = logical
% 0
isapprox(A,B)
% ans = logical
% 1
后言
篇幅問題很多更新不再贅述,其中包括幫助函數(shù)help
返回的信息格式會更加統(tǒng)一,還有一個對初學(xué)者很友好的更新,就是報錯的具體位置會用^這個符號進(jìn)行標(biāo)注,大概這樣:
然后簡單敘述一下關(guān)于文件處理的部分此外比如可以使用unzip
解壓有密碼的壓縮包,可以使用readdictionary
和writedictionary
讀取json文件,python和MATLAB字典可以互相使用:
- https://www.mathworks.com/help/releases/R2024b/matlab/matlab_external/use-matlab-dictionaries-in-python.html
- https://www.mathworks.com/help/releases/R2024b/matlab/matlab_external/python-dict-variables.html
此外在工具箱方面主要有以下更新
- 5G Toolbox - 探索候選 6G 波形生成
- DSP HDL Toolbox - 使用交互式 DSP HDL IP Designer 應(yīng)用程序定制、配置 DSP 算法并生成 HDL 代碼和驗證組件
- Simulink Control Design - 設(shè)計和實施非線性和數(shù)據(jù)驅(qū)動的控制技術(shù),例如滑動模式和迭代學(xué)習(xí)控制
- System Composer - 編輯子集視圖;使用活動和序列圖描述系統(tǒng)行為
更多詳細(xì)信息請見:
- https://www.mathworks.com/help/releases/R2024b/matlab/release-notes.html
- https://www.mathworks.com/products/new_products/latest_features.html