MATLAB 画圆

来源:互联网 发布:初高中网络培训机构 编辑:程序博客网 时间:2024/06/06 16:41
%=================alpha=0:pi/20:2*pi;%角度[0,2*pi]R=2;%半径x=R*cos(alpha);y=R*sin(alpha);plot(x,y,'o-')axis equal    %坐标轴的长度单位设成相等%=====================
function circle(R)alpha=0:pi/50:2*pi;%角度[0,2*pi] %R=2;%半径 x=R*cos(alpha); y=R*sin(alpha); plot(x,y,'-') axis equal 



matlab中无法只显示纵坐标或只显示横坐标。 但我可以教一个办法 set(gca,'XColor','white') set(gca,'Color','white') box off那有没有只显示坐标 不显示坐标上的数字的方法啊?试一下这个set(gca,'XColor','white') set(gca,'YColor','white') set(gca,'Color','white') box on

二维用法:zeros(m,n)或zeros(n)
功能:zeros(m,n)产生m×n的double类零矩阵,zeros(n)产生n×n的全0方阵。


box on 和off 显示出来的图形有没有四周的边框




1、坐标轴删除

set(gca,'xtick',[])%去掉x轴的刻度

set(gca,'ytick',[]) %去掉xy轴的刻度

set(gca,'xtick',[],'ytick',[]) %同时去掉x轴和y轴的刻度

2、Matlab中“坐标轴刻度”的不同风格 

x=1:8;

subplot(2,2,1)
plot(x)
%tick style 0(auto)


subplot(2,2,2)
plot(x)
set(gca,'xtick',[1 3 6 8]);%style 1
set(gca,'ytick',[]);%style 2

subplot(2,2,3)
plot(x)
set(gca,'xtick',[1 3 6 8]);
set(gca,'xticklabel',sprintf('.4f|',get(gca,'xtick')));%style3
set(gca,'ytick',[2 4 5 7]);
set(gca,'yticklabel',{'Two','Four','Five','Seven'});%style 4

subplot(2,2,4)
plot(x)
set(gca,'xminortick','on');%style 5
set(gca,'ticklength',[0.05 0.025]);%style 6
set(gca,'tickdir','out');%style 7

另附Maltab坐标调整程序一段:

x=20:10:20000;
y=rand(size(x));
semilogx(x,y);
set(gca,'XLim',[20 20000]);
set(gca,'XMinorTick','off');
set(gca,'XTick',[2031.5 63 125 250 500 1000 2000 4000 8000 16000]);
set(gca,'XGrid','on');
set(gca,'XMinorGrid','off');

 

3、matlab坐标刻度调整

subplot(3,2,1)

plot(x)

title('默认格式')

subplot(3,2,2)

plot(x)

set(gca,'xtick',[1 3 6 8]);

set(gca,'ytick',[]);

title('X自定义间隔,Y关闭')

subplot(3,2,3)

plot(x)

set(gca,'xtick',[1 3 6 8]);

set(gca,'xticklabel',sprintf('.4f|',get(gca,'xtick')))

set(gca,'ytick',[2 4 5 7]);

set(gca,'yticklabel',{'Two','Four','Five','Seven'});

title('XY自定义间隔、精度及显示方式')

subplot(3,2,4)

plot(x)

set(gca,'xminortick','on');%style 5

set(gca,'ticklength',[0.05 0.025]);

set(gca,'tickdir','out');

title('XY坐标刻度显示方式')

subplot(3,2,5)

plot(x)

set(gca,'xtick',[min(x) (max(x)+min(x))/2 max(x)]);

set(gca,'ytick',[min(x) (max(x)+min(x))/2 max(x)]);

title('论文中常用的标准3点式显示')

x=20:10:20000;

y=rand(size(x));

subplot(3,2,6)

semilogx(x,y);

set(gca,'XLim',[20 20000]);

set(gca,'XMinorTick','off');

set(gca,'XTick',[20 31.5 63 125 250 500 1000 2000 4000 800016000]);

set(gca,'XGrid','on');

set(gca,'XMinorGrid','off');

title('自定义网格显示')

%%%%%%%%%%%%%%%%%%%%%%

%顺便附上可以格式化坐标刻度的程序段

x=get(gca,'xlim');

y=get(gca,'ylim');

set(gca,'xtick',[x(1) (x(1)+x(2))/2 x(2)]);

set(gca,'ytick',[y(1) (y(1)+y(2))/2 y(2)]);

-------------

get(gca,'xlim');是获取最大最小刻度的

如果需要获取所有在坐标轴上显示的刻度,需要使用get(gca,'ytick')

clear; 清除原有变量clc; 清楚命令窗口的内容demo; 查看帮助help 查看帮助quit 退出matlabfigure 新建图形窗口

clf; 用来清除图形的命令。一般在画图之前用。








clearclcclf% ========给定初始值a,b;并得到函数u(x)==============a=2;b=7;lim=max([a,b,1]);x=0:0.1:1.5*lim;ux=zeros(1,length(x));for kk=1:length(x) if x(kk)>=0 && x(kk)<=a; ux(kk)=1; elseif x(kk)>a && x(kk)<=b; ux(kk)=(b-x(kk))/(b-a); else ux(kk)=0; endend% =========绘图============plot(x,ux,'r','Linewidth',2)set(gca,'XLim',[0 1.5*lim],... 'XTick',[a,b],... 'XTicklabel',('a|b'),... 'YLim',[0 1.5],... 'YTick',1)Xlabel('x')Ylabel('u(x)') ===end===========y轴没有设ab,因为函数最大值为1,如果ab初始设得比较大,反而会乱,所以只标注了1。如果一定要加ab,请设置合适值,在set语句下参考X轴 修改 YTick 并添加一行Yticklabel




0 0
原创粉丝点击