在x轴matlab图中重复数字

时间:2015-11-02 21:25:25

标签: matlab data-analysis

IEF % is a matrix have negative and positive values (1441 X 1)
T=linspace(0,24,1441);
figure,
plot(T,IEF)
grid on
set(gca,'xticklabel', 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24)

这段代码给了我一个x轴序列从0到24(小时)的图,但是数据是5天,所以我需要在X轴上重复0到24次。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我建议不要绘制24 * 5 = 120个数字,因为这样会使你的情节陷入困境。要么让MATLAB使用默认值,要么设置如下:

set(gca,'xticklabel', 0:24) %// for 24 hours, shorter of what you had above
set(gca,'xticklabel', 0:120) %// for 5 days
set(gca,'xticklabel', 0:6:120) %// for 5 days in steps of 6 hours

如果您想使用实际的24小时而不是0到120小时,请使用repmat

TimeHour = 0:6:24;
Time24Hour = 0:24;
TICKLABEL = repmat(TimeHour,1,5); %// change the 5 to how many days you want
TICKLABEL24 = repmat(Time24Hour,1,5); %// utilises 0:24 five times
set(gca,'xticklabel', TICKLABEL)
set(gca,'xticklabel', TICKLABEL24)