条形图在matlab中从数字更改x轴

时间:2017-04-15 17:02:14

标签: matlab graph

我想问一下如何从图表中更改数字1,2,3,4 ......我希望工作空间fnames.name中的变量图表中的日期(1 - > 11_08_2016_12_36没有.mat)。我尝试了一些函数句柄,但它不起作用。谢谢你的帮助。

Code Graph

This names I want change to graph

2 个答案:

答案 0 :(得分:0)

使用轴手柄。

data=rand(3,1);  

hfig = figure;
hax = axes;
hbar = bar(1:3,data);
dates={'Date 1';'Date 2';'Date 3'};
hax.XTickLabel=dates;
% In case you want your labels rotated. 
hax.XTickLabelRotation=90;

答案 1 :(得分:0)

N={fnames.name}; %isolate the names
t=zeros(1,length(N)); %reserve space
for ct = 1:length(N) %go over the names
    temp=regexp(N{ct},'\d\d_\d\d_\d\d\d\d_\d\d_\d\d','match'); %match the relevant part
    t(ct)=datenum([temp{:}],'mm_dd_yyyy_HH_MM'); %convert to datenum
end
%plot your graph here, use t as the x-axis%
datetick('x',1) %give x-axis in date