MATLAB: How to subscript in figures

figure labelsmatlab 2009subscriptUbuntu

Hello everyone,
I want to have subscript labels in axeses in matlab. Let say I have
J = [1 2 3; 4 5 6];
bar(J);
set(gca,'XTickLabel',{'I_0','I_1'});
I can't get I_0 in subscript. How can I do this. I m using Matlab 2009 on Ubuntu.

Best Answer

Here is one way, there may be others:
J = [1 2 3; 4 5 6];
bar(J);
set(gca,'XTickLabel','');
set(gca, 'XTickLabelMode','manual')
hxt = get(gca, 'XTick')
ypos = min(ylim) - diff(ylim)*0.05;
text(hxt, [1 1]*ypos, {'I_0','I_1'}, 'HorizontalAlignment', 'center')
You will have to experiment with the ypos value for text to put it exactly where you want it. I did my best to make it as adaptive as I could.