本文主要是介绍matlab绘图实例-多线图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- matlab线条设定
- 结果图常用设置(matlab)
- 一个完整的五线图绘制模板(matlab)
- 求多项式的根
matlab线条设定
matlab线条设定-官网
matlab线条设定2-官网
matlab默认风格
结果图常用设置(matlab)
linspace(起始值,终止值,元素个数)size(矩阵) % 获取矩阵的行列数length(向量) % 获取向量的长度data_box=xlsread('Data.xlsx'); % 将excel文件放在该matlab文件所在的路径中
一个完整的五线图绘制模板(matlab)
clc
clearx=linspace(-10,10,100);
y1=-x.^2;
y2=-2.*x.^2;
y3=-3.*x.^2;
y4=-4.*x.^2;
y5=-5.*x.^2;% matlab元组(cell)的使用:元组的一个元素可以存储一个矩阵
box{1}(:,1)=x; box{1}(:,2)=y1;
box{2}(:,1)=x; box{2}(:,2)=y2;
box{3}(:,1)=x; box{3}(:,2)=y3;
box{4}(:,1)=x; box{4}(:,2)=y4;
box{5}(:,1)=x; box{5}(:,2)=y5;%=====================================================================
figure(1);
plot(x,y1,'--r','LineWidth',2,'MarkerSize',7); hold on;
plot(x,y2,'-.b','LineWidth',2,'MarkerSize',7); hold on;
plot(x,y3,'-k','LineWidth',2,'MarkerSize',7); hold on;
plot(x,y4,'--.g','LineWidth',2,'MarkerSize',10); hold on;
plot(x,y5,':m','LineWidth',2,'MarkerSize',7); hold on;
%---------------------------------------------------------------------
set(legend('$k=1$',...'$k=2$',...'$k=3$',...'$k=4$',...'$k=5$',...'Location','south'),'Interpreter','latex','FontSize',15,'fontname','Times New Roman')
% north south west east
%---------------------------------------------------------------------
set(gca,'FontSize',15,'fontname','Times New Roman') %是设置刻度字体大小
% set(gca, 'YScale', 'log')
% set(gca, 'XScale', 'log')
set(gca, 'XLim', [-10,10])
set(gca, 'YLim', [-500,0])
xlabel('$x$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
ylabel('$y=kx^2$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
%---------------------------------------------------------------------
% 标注极值点
% [极值,极值点]=max(向量); %获取最大值点和最大值
% [~,极值点]=max(向量); %获取最大值点
%---------------------------------------------------------------------
% 导出高分辨率(700)png图片
img1 =gcf; %获取当前画图的句柄
print(img1, '-dpng', '-r700', './img1.png') %=====================================================================
figure(2);
plot(box{1}(:,1),box{1}(:,2),'--','Color',[126,47,142]/255,'LineWidth',2,'MarkerSize',7); hold on;
plot(box{2}(:,1),box{2}(:,2),'-.','Color',[217, 83, 25]/255,'LineWidth',2,'MarkerSize',7); hold on;
plot(box{3}(:,1),box{3}(:,2),'-','Color',[255,0,0]/255,'LineWidth',2,'MarkerSize',7); hold on;
plot(box{4}(:,1),box{4}(:,2),'--.','Color',[237, 177, 32]/255,'LineWidth',2,'MarkerSize',10); hold on;
plot(box{5}(:,1),box{5}(:,2),':','Color',[0,144,189]/255,'LineWidth',2,'MarkerSize',7); hold on;
%---------------------------------------------------------------------
set(legend('$k=1$',...'$k=2$',...'$k=3$',...'$k=4$',...'$k=5$',...'Location','south'),'Interpreter','latex','FontSize',15,'fontname','Times New Roman')
% north south west east
%---------------------------------------------------------------------
set(gca,'FontSize',15,'fontname','Times New Roman') %是设置刻度字体大小
% set(gca, 'YScale', 'log')
% set(gca, 'XScale', 'log')
set(gca, 'XLim', [-10,10])
set(gca, 'YLim', [-500,0])
xlabel('$x$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
ylabel('$y=kx^2$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
%---------------------------------------------------------------------
% 标注极值点
% [极值,极值点]=max(向量); %获取最大值点和最大值
% [~,极值点]=max(向量); %获取最大值点
%---------------------------------------------------------------------
% 导出高分辨率(700)图片
img2 =gcf; %获取当前画图的句柄
print(img2, '-dpng', '-r700', './img2.png')
% 结果显示精度设置format short
format long% 科学计数法
format short e
format long e% 没有科学计数法
format short g
format long g
设置刻度
xticks([0 5 10])
xticklabels({'x = 0','x = 5','x = 10'})中英文混用(tex解释器、部分字体设置)xlabel('再生骨料取代率\alpha Gpa{\fontname{Times New Roman} \alpha Gpa }','Interpreter','tex','FontSize',20,'fontname','Songti')
ylabel('$y=kx^2$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
annotation('arrow',[0.567857142857142 0.137499999999999],...[0.571428571428578 0.571428571428578]);
annotation('textbox',...[0.568857142857142 0.530952382655372 0.267865037279234 0.0809523792493911],...'String','$r_1=0.1 \to 10$',...'Interpreter','latex',...'FontSize',15,...'FitBoxToText','off',...'EdgeColor','none');
求多项式的根
% 求alpha2
% a7=8400*aa_*alpha1^2*etaa^2*fss^2*hh0*k*lambdak^2 - 637*EE*alpha1^2*k*lambdaE^2;
% a6=10800*aa_*alpha1^2*etaa^2*fss^2*hh0^2*lambdak^2 - 10800*Css0*alpha1^2*lambdaE^2;
% a5=0;
% a4=9600*aa_*alpha1*etaa*fss^2*hh0*k*lambdak^2;
% a3=10800*aa_*alpha1*etaa*fss^2*hh0^2*lambdak^2 + 150*EE*I1*k^3 - 180*EE*k^3*lambdak^2;
% a2=450*EE*I1*hh0*k^2 - 450*EE*hh0*k^2*lambdak^2;
% a1=1200*aa_*fss^2*hh0^2*k*lambdak^2 - 1800*I1*aa_*fss^2*hh0*k + 1800*I1*gg*hh0^2*k + 450*EE*I1*hh0^2*k - 1200*gg*hh0^2*k*lambdak^2 - 300*EE*hh0^2*k*lambdak^2;
% a0=1800*I1*Kss0*hh0^2;
% roots([a7 a6 a5 a4 a3 a2 a1 a0]) % 通过输入各阶系数求多项式的根。
factor_min=0.32;
factor_max=0.001;
CircleNum=1000;
for jj=1:CircleNum+1
factor = factor_min + (factor_max - factor_min)*((jj-1)/CircleNum)^2;
box(jj,1)=factor; end
clc
clearx=linspace(-10,10,20);
y1=-x.^2;
y2=-2.*x.^2;
y3=-3.*x.^2;
y4=-4.*x.^2;
y5=-5.*x.^2;% matlab元组(cell)的使用:元组的一个元素可以存储一个矩阵
box{1}(:,1)=x; box{1}(:,2)=y1;
box{2}(:,1)=x; box{2}(:,2)=y2;
box{3}(:,1)=x; box{3}(:,2)=y3;
box{4}(:,1)=x; box{4}(:,2)=y4;
box{5}(:,1)=x; box{5}(:,2)=y5;%=====================================================================
figure(1);
plot(x,y1,'-or','LineWidth',1.5,'MarkerSize',8); hold on;
plot(x,y2,'-^b','LineWidth',1.5,'MarkerSize',8); hold on;
plot(x,y3,'-s','LineWidth',1.5,'MarkerSize',8); hold on;
plot(x,y4,'-dg','LineWidth',1.5,'MarkerSize',8); hold on;
plot(x,y5,'-hm','LineWidth',1.5,'MarkerSize',8); hold on;
%---------------------------------------------------------------------
set(legend('$k=1$',...'$k=2$',...'$k=3$',...'$k=4$',...'$k=5$',...'Location','south'),'Interpreter','latex','FontSize',15,'fontname','Times New Roman')
% north south west east
%---------------------------------------------------------------------
set(gca,'FontSize',15,'fontname','Times New Roman') %是设置刻度字体大小
% set(gca, 'YScale', 'log')
% set(gca, 'XScale', 'log')
set(gca, 'XLim', [-10,10])
set(gca, 'YLim', [-500,0])
xlabel('$x$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
ylabel('$y=kx^2$','Interpreter','latex','FontSize',20,'fontname','Times New Roman')
%---------------------------------------------------------------------
% 标注极值点
% [极值,极值点]=max(向量); %获取最大值点和最大值
% [~,极值点]=max(向量); %获取最大值点
%---------------------------------------------------------------------
% 导出高分辨率(700)png图片
img1 =gcf; %获取当前画图的句柄
print(img1, '-dpng', '-r700', './img1.png') %=====================================================================
这篇关于matlab绘图实例-多线图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!