我想問我怎樣才能改變數字1,2,3,4 ...從圖形,我想日期(1 - > 11_08_2016_12_36沒有.mat)在圖中來自工作區fnames.name中的變量。我嘗試了一些函數句柄,但它不起作用。謝謝你的幫助。從matlab中的數字到數據的條形圖變化x軸
0
A
回答
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
使用軸手柄。
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;
這是我的解決方案,但感謝您的幫助: '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°' –