matlab - 如何在 MATLAB 中绘制日期时间的差异?
问题描述
我在不同时间测量了值,我想绘制它们。在 excel 文件中,列的时间和值是分开的。时间格式为:HH:MM:SS 例如:11:20:21。我想在 x 轴上绘制时间之间的差异(以秒为单位)。y 轴将是测量值。我从 excel 文件中读取数据,但不知道如何绘制 x 轴。例如:excel 中的数据:10:20:33,10:20:35,10:20:39 和 x 轴上的值是:0,2,4(以秒为单位)。这是我的开始:
V1= xlsread('measured.xlsx','D4:D5295')
V2= xlsread('measured.xlsx','E4:E5295')
CV= xlsread('measured.xlsx','F4:F5295')
t=xlsread('measured.xlsx','B4:B5295')
plot(t,V1,t,V2,t,CV)
datetick('x',13)
title('Measurement')
ylabel('Data [V]')
xlabel('time [s]')
有了这个,我得到了 x 轴日期,但我想得到两个测量时间之间经过的时间。
解决方案
我要做的是将时间向量转换为“datatime”数据类型,计算时间之间的差异(使用 diff 命令),然后将其转换为秒。
V1= xlsread('measured.xlsx','D4:D5295')
V2= xlsread('measured.xlsx','E4:E5295')
CV= xlsread('measured.xlsx','F4:F5295')
t=xlsread('measured.xlsx','B4:B5295')
% convert it to datatime data type
t = datetime(t);
% Get the difference between times and add the "0" to keep
% the same vector size.
t = [0; seconds(diff(t))];
plot(t,V1,t,V2,t,CV)
datetick('x',13)
title('Measurement')
ylabel('Data [V]')
xlabel('time [s]')
推荐阅读
- django - 从视图中保存查询时出现不完整错误
- json - 为什么隐式读取找不到我的对象类型scala
- sql - 在“_”第三次出现后返回文本
- elasticsearch - 仅查询 _Source 文档中的键(跳过值)
- xamarin.forms - 如何使用 xamarin 表单在 android 9 中获取活动的 Wifi 网络运营商名称
- c# - ASP.Net MVC5 检查类是否已经在内存中
- php - Wordpress 仅显示 1 个自定义帖子类型而不是 2 个
- javascript - React - Redux 在渲染组件之前等待获取结果
- imagemagick - 如何在imageMagick中更改带水印的图像背景
- intellij-idea - 我的项目开始在构建时抛出错误 NegativeArraySizeException