Matlab的XTickLabel中数值带下标

%axis为'x'或'y',分别表示更改x或y刻度
%ticks是字符cell
function settick(axis,ticks)
n=length(ticks);
tkx=get(gca,'XTick');tky=get(gca,'YTick');
switch axis
case 'x'
w=linspace(tkx(),tkx(end),n);
set(gca, 'XTick', w, 'XTickLabel', []);%刷新刻度,去掉刻度值
yh=(*w()-w(end))/;%按坐标轴比例调整刻度纵坐标位置
for i=:n
text('Interpreter','tex','String',ticks(i),'Position',[w(i),yh],'horizontalAlignment', 'center');
end
case 'y'
w=linspace(tky(),tky(end),n);
set(gca, 'YTick', w, 'YTickLabel', []);
xh=(*w()-w(end))/;
for i=:n
text('Interpreter','tex','String',ticks(i),'Position',[xh,w(i)],'horizontalAlignment', 'center');
end
end

例如:
>> x=0:0.1:4*pi;plot(x,sin(x));ticks={'G_1'  'G_2'  'G_3'  'G_4'  'G_5'};settick('x',ticks)
>> figure;x=0:0.1:4*pi;plot(x,sin(x));ticks={'G_1'  'G_2'  'G_3'  'G_4'  'G_5'};settick('y',ticks)

from: http://www.ilovematlab.cn/thread-39718-1-1.html

上一篇:实战fortran77基础语法


下一篇:max10中对DDR数据的采样转换