您当前的位置: 首页 >  matlab

slandarer

暂无认证

  • 0浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MATLAB | 怎么让MATLAB自己生成代码?

slandarer 发布时间:2022-09-14 11:51:10 ,浏览量:0

国赛就是明天了,写了个很有意思的东西,虽然目前只是个雏形但是,这玩意真的挺有意思的,很多人写完基础代码绘图后不咋修饰就点开属性编辑器一顿点点点,但这样画出的图毕竟只有图没有相关代码,有没有啥办法能够把点点点的过程转化为代码,能把论文写的更长一点?于是就有了下面这个小工具,首先介绍用法,最后给出工具函数完整代码(初代懒得写注释ing):

基本使用

写完绘图函数后在代码最后加入一行codeprinter

t=0.01:0.2:3*pi;
hold on
plot(t,cos(t)./(1+t),'LineWidth',2)
plot(t,sin(t)./(1+t),'LineWidth',2)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',2)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',2)
legend

codeprinter

点击:查看->属性编辑器

进行一通编辑:

关闭窗口后就能自动在命令行窗口生成一系列代码:

删掉代码末尾的codeprinter,把命令行的代码加载最后,能获取之前全部修饰效果,美滋滋:

t=0.01:0.2:3*pi;
hold on
plot(t,cos(t)./(1+t),'LineWidth',2)
plot(t,sin(t)./(1+t),'LineWidth',2)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',2)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',2)
legend

fig=gcf;
fig.Children(1).FontName='Cambria';
fig.Children(1).FontSize=11;
fig.Children(1).LineWidth=2;
fig.Children(1).Location='southeast';
fig.Children(1).NumColumns=4;
fig.Children(1).Orientation='horizontal';
fig.Children(1).Position=[0.4103, 0.12433, 0.48022, 0.028419];
fig.Children(1).Title.FontName='Cambria';
fig.Children(1).Title.FontSize=11;
fig.Children(2).XColor=[1, 0, 0];
fig.Children(2).XTick=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
fig.Children(2).XTickLabel={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
fig.Children(2).YColor=[1, 0, 0];
fig.Children(2).ZColor=[1, 0, 0];
fig.Children(2).LineWidth=2;
fig.Children(2).XGrid='on';
fig.Children(2).YGrid='on';
fig.Children(2).Box='on';
fig.Children(2).Title.Position=[5, 1.0061, -1.4211e-14];
fig.Children(2).Title.String='demo of codeprinter';
fig.Children(2).Title.FontName='Cambria';
fig.Children(2).Title.FontSize=16;
fig.Children(2).Subtitle.Position=[5, 1.0042, -1.4211e-14];
fig.Children(2).XLabel.Color=[1, 0, 0];
fig.Children(2).XLabel.Position=[5, -0.4549, -1];
fig.Children(2).YLabel.Color=[1, 0, 0];
fig.Children(2).YLabel.Position=[-0.58126, 0.3, -1];
fig.Children(2).ZLabel.Color=[1, 0, 0];
fig.Children(2).Children(4).LineWidth=4;
fig.Children(2).Children(4).Marker='            
关注
打赏
1664692598
查看更多评论
0.0442s