行业知识
MATLAB | R2024a更新了哪些好玩的东西?
2026-11-08 22:12:43
来源:互联网转载
Hey 好久不见,大家一看三月中下旬这个时间节点也应该能猜到这篇更新什么内容,没错MATLAB R2024a正式版发布啦啦拉拉,直接来看看有啥我认为比较有意思的更新点吧:
1 极坐标表达式绘制
将会使用使用fpolarplot函数来替换ezpolar:
f = @(t) 1 + cos(t);fpolarplot(f)% fpolarplot(f,LineWidth=2)
2 极坐标填充区域
使用thetaregion,radiusregion和polarregion函数。填充区域用于高亮显示绘图:
f = @(t) 1 + cos(t);fpolarplot(f,LineWidth=2)% 极坐标半径填充radiusregion([0.5,1],'FaceColor','b')% 极坐标角度填充thetaregion([pi/6,pi/3]+pi,'FaceColor','g')% 极坐标区域填充thetas = [0 pi/2];radii = [1.5 2];polarregion(thetas,radii,'FaceColor','r')
3 线条样式
可以使用linestyleorder函数设置线条样式的出现规律:
Y = (10:15)'-(0:5);tiledlayout(2,1)ax1 = nexttile;plot(ax1,Y,LineWidth=1)ax2 = nexttile;plot(ax2,Y,LineWidth=1)% 设置坐标区域1线条样式linestyles1 = ["-","--","-o"];linestyleorder(ax1, linestyles1)% 设置坐标区域2线条样式linestyles2 = ["-s","-.","->"];linestyleorder(ax2, linestyles2)
4 RGB和16进制颜色转换
rgb2hex和hex2rgb:
RGB = [0.60 0.30 0.80];rgb2hex(RGB)% ans = % "#994DCC"hexStr = "#CD00EF";hex2rgb(hexStr)% ans = 1×3% 0.8039 0 0.9373
当然我很久很久以前写过类似的东西:
function string=ten2sixteen(num)%the num should be a 1x3 Integer mat limited in [0 255]exchange_list={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};string='#';for i=1:3 temp_num=num(i); string(1+i*2-1)=exchange_list{(temp_num-mod(temp_num,16))/16+1}; string(1+i*2)=exchange_list{mod(temp_num,16)+1};endend% ten2sixteen([20,30,255])% ans =% '#141EFF'function num=sixteen2ten(string) exchange_list='0123456789ABCDEF#'; num=zeros(1,3); for i=1:3 tempCoe1=find(exchange_list==string(i*2))-1; tempCoe2=find(exchange_list==string(i*2+1))-1; num(i)=16*tempCoe1+tempCoe2; endend% sixteen2ten('#26FF06')% ans =% 38 255 6 5 图例及矩形透明度
您可以控制图例框和矩形的透明度:
- 通过设置BackgroundAlpha的属性,将图例对象透明度设置为介于0(完全透明)和 1(不透明)
- 通过设置FaceAlpha的属性,将矩形对象透明度设置为介于0和1 .
说来有趣,之前参加迷你黑客大赛后,官方Graphics Team询问有没有想要分享的技巧:
我就分享了关于实现圆角半透明图例的知乎文章:
- https://zhuanlan.zhihu.com/p/642487014
然后比较巧的是,官方团队正好也打算在R2024a版本发布这个功能,属于正巧撞上了:
X=1:2;Y=(1:2)+(1:6)';plot(X,Y,'LineWidth',8);legend('BackgroundAlpha',.5)展示一下我之前写的功能函数和效果:
function SPrettyLegend(lgd)% Semitransparent rounded rectangle legend% Copyright (c) 2023, Zhaoxu Liu / slandarer% -------------------------------------------------------------------------% Zhaoxu Liu / slandarer (2023). pretty legend % (https://www.mathworks.com/matlabcentral/fileexchange/132128-pretty-legend), % MATLAB Central File Exchange. 检索来源 2023/7/9.% =========================================================================if nargin
- https://zhuanlan.zhihu.com/p/642487014
下一篇:2012服务器怎么建站?