Matlab绘制XTickLabel有效字符串(Matlab Plot XTickLabel valid strings)
我有一个情节:
x = [0 1 2 3];
y = [0 0 1 1];
plot (x, y, 'k');
我想在X轴上使用标签,它可以工作:
set(gca,'XTick',[0:3]) % This automatically sets
labels = ['0'; 'T'; 'T'; '1';];
set(gca,'XTickLabel',labels)
但是,当我将T改为T0 。 它不起作用。
Q1: XTickLabel的有效字符串是XTickLabel ?
Q2:如何使用T0,T1之类的字符串。 或者是否可以在乳胶格式中使用像$ A_2 $这样的子索引字符。
I have a plot:
x = [0 1 2 3];
y = [0 0 1 1];
plot (x, y, 'k');
I want to use labels at X-axis, and it works:
set(gca,'XTick',[0:3]) % This automatically sets
labels = ['0'; 'T'; 'T'; '1';];
set(gca,'XTickLabel',labels)
However, when I change T to T0. It doesn't work.
Q1: What are the valid strings of XTickLabel?
Q2: How can I use strings like T0, T1. Or is that possible to use characters with subindex like $A_2$ in latex format.
原文:https://stackoverflow.com/questions/11174326
2020-02-13 22:02
满意答案
如果要设置不同长度的字符串,则需要使用单元格数组,即
labels = {'0','T','T0','somethingCompletelyDifferent'}
将工作。
如果要使用Latex格式化刻度标签,则需要从Matlab文件交换中下载一个函数 。
If you want to set strings of different lengths, you need to use cell arrays, i.e.
labels = {'0','T','T0','somethingCompletelyDifferent'}
will work.
If you wan