Matlab具有强大的数据绘图功能,可以通过 Figure 绘制 BP 神经网络图,并保存矢量图,具体代码如下
figure("name","BP figure")
x1 = ones(1, 5);
x2 = 2 * ones(1, 11);
x3 = 3 * ones(1, 8);
y1 = 4:8;
y2 = 1:11;
y3 = 2.5:9.5;
for i = 1:5
for j = 1:11
plot([x1(i), x2(j)], [y1(i), y2(j)], 'k');
hold on
end
end
for i = 1:11
for j = 1:8
plot([x2(i), x3(j)], [y2(i), y3(j)], 'k');
end
end
scatter(x1, y1, 200, 'k', 'MarkerFaceColor', 'r');
scatter(x2, y2, 200, 'k', 'MarkerFaceColor', 'y');
scatter(x3, y3, 200, 'k', 'MarkerFaceColor', 'k');
x1 = xline(1.5,'k--');
x1.LineWidth = 1;
x2 = xline(2.5,'k--');
x2.LineWidth = 1;
ylim([0.5 11])
text(1.5,11.6,"\fontname{宋体}输入层",...
'HorizontalAlignment','center',...
"fontsize",10)
text(2,11.6,"\fontname{宋体}隐藏层" ,...
'HorizontalAlignment','center', ...
"fontsize",10)
text(2.5,11.6,"\fontname{宋体}输出层" ,...
'HorizontalAlignment','center', ...
"fontsize",10)
axis off
savefig(gcf,"BP_figure.fig")
print(gcf,'-dtiff','-r600',"BP_figure")