Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在matlab中,条形图将x轴从数字更改为日期_Matlab_Graph - Fatal编程技术网

在matlab中,条形图将x轴从数字更改为日期

在matlab中,条形图将x轴从数字更改为日期,matlab,graph,Matlab,Graph,我想问我怎样才能改变数字1,2,3,4。。。从图中,我想从workspace fnames.name中的变量中获取图中的日期(1->11_08_2016_12_36,不带.mat)。我尝试了一些函数句柄,但不起作用。谢谢你的帮助 使用轴手柄 data=rand(3,1); hfig = figure; hax = axes; hbar = bar(1:3,data); dates={'Date 1';'Date 2';'Date 3'}; hax.XTickLabel=dates; %

我想问我怎样才能改变数字1,2,3,4。。。从图中,我想从workspace fnames.name中的变量中获取图中的日期(1->11_08_2016_12_36,不带.mat)。我尝试了一些函数句柄,但不起作用。谢谢你的帮助

使用轴手柄

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;

我想从workspace fname.name(其中我有41个date)自动将数字从graph更改为date,因此,假设fname.name也是一个单元格数组,则每列都将是变量fname.nameChanges
dates=
fname.name=
的日期。我没有这样写,因为您没有指定fname.name是单元格数组还是字符串数组;它是一个包含字符数组的结构吗?在这种情况下,您可以使用struct2cell()将其带到单元格数组中,并将其放入轴句柄中。我附加了变量fnames.name的图片,希望在图形中对其进行更改。这是我的解决方案,但感谢您的帮助:
handle=gca;x_label=strtok({fnames.name},'.');%从文本x_label=strrep中删除“.mat”(x_label,”,“/”);%因为MATLAB将“u”作为索引,所以我将其更改为“/”set(handle,'XTick'[1:size(fnames,1)],'XTickLabel',x_标签,'XTickLabelRotation',45)%%选择具有可变大小的x_标签并旋转45°
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