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')));