Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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_Date_Axis Labels - Fatal编程技术网

Matlab绘图中的X轴日期错误

Matlab绘图中的X轴日期错误,matlab,date,axis-labels,Matlab,Date,Axis Labels,我的日期格式为“yyyymmdd”。当我把这些放在绘图的X轴上时,我得到了疯狂的数字。我的绘图间隔是过去十年,但X轴刻度标签显示的是1979年和其他奇怪的数字。有人能给我指出正确的方向来纠正这个问题吗?谢谢 编辑:以下是请求的代码: TradeDate=TradeDate+693960; % convert excel serial dates to matlab serial dates TradeDate=datestr(TradeDate,'mmddyyyy'); % convert th

我的日期格式为“yyyymmdd”。当我把这些放在绘图的X轴上时,我得到了疯狂的数字。我的绘图间隔是过去十年,但X轴刻度标签显示的是1979年和其他奇怪的数字。有人能给我指出正确的方向来纠正这个问题吗?谢谢

编辑:以下是请求的代码:

TradeDate=TradeDate+693960; % convert excel serial dates to matlab serial dates
TradeDate=datestr(TradeDate,'mmddyyyy'); % convert the format into yyyymmdd
TradeDate=str2double(cellstr(TradeDate)); % convert the date strings first into cell arrays and then into a double

plot(TradeDate,beta);
xlabel('Date');
ylabel('Beta');
daspect([300 1 1]);
set(gca,'xtick',linspace(TradeDate(1),TradeDate(1715),50));
ax=gca;
ax.XTickLabelRotation=45;

您正在做的是在
x
-轴上绘制序列日期编号,而我怀疑您实际上想要绘制日期字符串本身

因此,首先使用序列日期号生成绘图,然后通过更改
x
-轴标签来使用日期字符串。顺便说一句,您使用str2double的代码是毫无意义的,因为如果我正确地遵循您对第一行代码的注释,这已经是一个连续日期了

大概是这样的:

TradeDate=TradeDate+693960; % convert excel serial dates to matlab serial dates

%// Note change in variable name here and convert to cell array of strings
TradeDates=cellstr(datestr(TradeDate,'mmddyyyy')); % convert the format into mmddyyy

plot(TradeDate,beta);
xlabel('Date');
ylabel('Beta');
daspect([300 1 1]);
set(gca,'xtick',linspace(TradeDate(1),TradeDate(1715),50));
%// Change - Change x-axis labels
set(gca, 'XTickLabel', TradeDates(1:50:1715));
ax=gca;
ax.XTickLabelRotation=45;

现在,我有了在一年的第一个数字后加上句号的记号标签(例如,20080117显示为2.0081。我正在玩datetick,但迄今为止没有任何成功。你能给我们看一下你的代码来重建你的问题吗?我猜你正在使用
x
-轴上的原始日期数。你只需使用
datestr
@rayryeng将它们重命名为正确的日期即可。请参阅上面发布的代码。谢谢e无法自行运行。存在未定义的变量…如
1Date
。此外,
TradeDate
未使用。@rayryeng抱歉,TradeDate应该代替1Date。