本文主要是介绍Matlab画一个直角坐标系,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Matlab画一个直角坐标系
Code:
% 画一个直角坐标系
fig1 = figure(1); hold on;
axis2d_yxl(fig1,-10:10,-2:1.5); % x轴和y轴的显示范围function axis2d_yxl(fig,x_range,y_range)figure(fig);hold on;% 确定横轴范围x=[x_range,x_range+1];% 确定纵轴范围y=[y_range,y_range+1];% 画横纵轴plot([0 0],[min(y)-1 max(y)+1],'k','LineWidth',1);plot([min(x)-1 max(x)+1],[0 0],'k','LineWidth',1);% 画箭头ax=[max(x)+1,max(x),max(x);0,0.1,-0.1];fill(ax(1,:),ax(2,:),'k');ay=[0, 0.1,-0.1;max(y)+1,max(y),max(y)];fill(ay(1,:),ay(2,:),'k');% 标记O,x,ytext(-0.3,-0.3, 'O','FontName','Times New Roman','FontAngle','Italic','FontSize',12,'LineWidth',10,'HorizontalAlignment','center','FontWeight','bold');text(max(x)+0.3, -0.3, 'x','FontName','Times New Roman','FontAngle','Italic','FontSize',14,'LineWidth',10,'VerticalAlignment','middle','FontWeight','bold');text(0.4, max(y)+0.5, 'y', 'FontName','Times New Roman','FontAngle','Italic','FontSize',14,'LineWidth',10,'HorizontalAlignment','center','FontWeight','bold');% 坐标轴刻度for i=1:length(x)-1if x(i)~=0plot([x(i),x(i)],[0,0.1],'k'); a=text(x(i),-0.4,num2str(x(i)));set(a,'FontName','Helvetica','FontSize',10,'LineWidth',10,'HorizontalAlignment','center');endendfor i=1:length(y)-1if y(i)~=0plot([0,0.1],[y(i),y(i)],'k'); b=text(-0.4,y(i),num2str(y(i)));set(b,'FontName','Helvetica','FontSize',10,'LineWidth',10,'HorizontalAlignment','center');endend% 关闭原有坐标系axis off;% 使x轴和y轴的单位长度相同axis equal;
end
Photo:
这篇关于Matlab画一个直角坐标系的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!