matlab dateform,Matlab:將日期導入的excel轉換為可讀格式?

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值