clear;clc
xlim([0,100]);
grid on
set(gca,'xtick',0:100);
a=get(gca,'xticklabel');
b=repmat(' ',size(a));
b(mod(1:size(a,1),10)==1,:)=a(mod(1:length(a),10)==1,:);
set(gca,'xticklabel',b);
2020-9-5:2017版后a从char类型变成了cell类型,修改如下
clear;clc
xlim([0,100]);
grid on
set(gca,'xtick',0:100);
a=get(gca,'xticklabel');
b=cell(size(a));
b(mod(1:size(a,1),10)==1,:)=a(mod(1:length(a),10)==1,:);
set(gca,'xticklabel',b);
改变坐标轴显示数值,可以用set(gca,'xtick',xtick,'xticklabel',xticklabel) ;gca表示Get Current Axis的Handle,xtick表示显示刻度的位置,xticklabel表示显示的内容。
Example:
>> x = -pi:0.1:pi;
>> y = sin(x);
>> plot(x,y);
>> set(gca,'XTick',-pi:pi/2:pi);
>> set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'});
>> title('sine function');
>> title('Sine Function');
>> xlabel('Radians');
>> ylabel('Function Value');