2017-04-15 63 views

回答

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 
+0

這是我的解決方案,但感謝您的幫助: 'handle = gca; x_label = strtok({fnames.name},'。'); %%從文本中刪除「.mat」 x_label = strrep(x_label,'_','/');因爲MATLAB以「_」作爲索引,所以我將其更改爲「/」 set(handle,'XTick'[1:size(fnames,1)],'XTickLabel',x_label,'XTickLabelRotation',45) %%選擇x_label與可變大小和旋轉45°' –

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; 
+0

我想自動號碼從圖表迄今從工作區fname.name其中i有41日期改變,因此每列將是從變量fname.name –

+0

變化'日期='與日期'fname.name ='假定fname.name也是一個單元格數組。我沒有這樣寫,因爲你沒有指定fname.name是一個單元格數組還是字符串數組。 – Poelie

+0

我沒有注意到你截圖了你的代碼;它是一個帶有字符數組的結構嗎?在這種情況下,您可以使用struct2cell()將其引入單元格數組並將其放入軸手柄中。 – Poelie