I have imported data from excel file. After importing date date, my date looks like:
我从excel文件导入了数据。导入日期日期后,我的日期如下:
0.641238425925926
0.641932870370370
0.642627314814815
0.643321759259259
0.644016203703704
I used datestr(Time)
. I am getting date data in the format I need, however the data is not in tabular format. I need to plot the data. So I need to have all of it in tabular format.
我用了datestr(时间)。我以我需要的格式获取日期数据,但数据不是表格格式。我需要绘制数据。所以我需要以表格格式提供所有内容。
datevec
works, however, it gives Hour, Minute separately. Not sure how to combine it all.
但是,datevec有效,它分别给出小时,分钟。不知道如何将它们结合起来。
Is there a work around?
有工作吗?
1 个解决方案
#1
0
If you expect those numbers to be full dates (and by "full dates" I mean temporal points including both a date and a time), then you are probably doing something wrong when reading the Excel spreadsheet. But since you are only speaking about hours and minutes, I think you are on the right path and you only want to consider time.
如果您希望这些数字是完整日期(并且“完整日期”我的意思是时间点,包括日期和时间),那么您在阅读Excel电子表格时可能会出错。但由于你只是说几小时和几分钟,我认为你走在正确的道路上,你只想考虑时间。
time = [
0.641238425925926
0.641932870370370
0.642627314814815
0.643321759259259
0.644016203703704
];
time_str = cellstr(datestr(data,'HH:mm:ss'));
The above code will produce a 5-by-1 cell array of character vectors, which is not good for plotting. As you said, datevec
will split your datetime values, and it's not good either. I suggest you to keep your values into their current numeric format and use them in order to define your x-axis
points. Once the plot is drawn, you can always convert your tick labels into a more readable format:
上面的代码将生成一个5乘1的字符向量数组,这对绘图不利。正如你所说,datevec将分割你的日期时间值,它也不好。我建议你将你的值保持为当前的数字格式并使用它们来定义你的x轴点。绘制绘图后,您始终可以将刻度标签转换为更易读的格式:
time = [
0.641238425925926
0.641932870370370
0.642627314814815
0.643321759259259
0.644016203703704
];
value = [
1
3
4
0
2
];
plot(time,value);
datetick('x','HH:mm:ss');
As you can see, this loses the seconds precision because of rounding. So, to keep the highest possible precision:
正如您所看到的,由于四舍五入,这会失去秒精度。因此,要保持尽可能高的精度:
% ...
plot(time,value);
set(gca,'XTickLabel',cellstr(datestr(data,'HH:mm:ss')));
#1
0
If you expect those numbers to be full dates (and by "full dates" I mean temporal points including both a date and a time), then you are probably doing something wrong when reading the Excel spreadsheet. But since you are only speaking about hours and minutes, I think you are on the right path and you only want to consider time.
如果您希望这些数字是完整日期(并且“完整日期”我的意思是时间点,包括日期和时间),那么您在阅读Excel电子表格时可能会出错。但由于你只是说几小时和几分钟,我认为你走在正确的道路上,你只想考虑时间。
time = [
0.641238425925926
0.641932870370370
0.642627314814815
0.643321759259259
0.644016203703704
];
time_str = cellstr(datestr(data,'HH:mm:ss'));
The above code will produce a 5-by-1 cell array of character vectors, which is not good for plotting. As you said, datevec
will split your datetime values, and it's not good either. I suggest you to keep your values into their current numeric format and use them in order to define your x-axis
points. Once the plot is drawn, you can always convert your tick labels into a more readable format:
上面的代码将生成一个5乘1的字符向量数组,这对绘图不利。正如你所说,datevec将分割你的日期时间值,它也不好。我建议你将你的值保持为当前的数字格式并使用它们来定义你的x轴点。绘制绘图后,您始终可以将刻度标签转换为更易读的格式:
time = [
0.641238425925926
0.641932870370370
0.642627314814815
0.643321759259259
0.644016203703704
];
value = [
1
3
4
0
2
];
plot(time,value);
datetick('x','HH:mm:ss');
As you can see, this loses the seconds precision because of rounding. So, to keep the highest possible precision:
正如您所看到的,由于四舍五入,这会失去秒精度。因此,要保持尽可能高的精度:
% ...
plot(time,value);
set(gca,'XTickLabel',cellstr(datestr(data,'HH:mm:ss')));