导入 MATLAB 时时间列变为十进制形式
Time column changes into decimal form when imported to MATLAB
我有来自 Excel 中 xlxs 文件的数据集,我必须将其导入 MATLAB。问题是每当我导入数据时,时间总是以小数形式出现。
所以在这里,xlxs文件中的数据显示格式为HH:MM:SS:
这是在 MATLAB 的导入助手中的样子
我要为它生成折线图,它是这样的:
这是我用来生成绘图的示例代码,其中我希望时间不以十进制形式显示。
datestr(Time,'HH:MM:SS');
title ('Particle Measurement for 02-20-2020 @ UPD')
plot(Time,PM10)
xlabel('Time')
ylabel('Particle Measurement')
hold on
plot(Time,PM1)
hold on
plot(Time,PM25)
MATLAB 中的时间 datenum()
values, which are decimal days since 0 Jan 0000. So the things you see are correct times. You can use datestr(Time,'HH:mm:ss')
to get a string for the time, and datetick('x','HH:mm')
以小时为单位获取轴上的刻度线。
代码中的 datestr(Time,'HH:MM:SS');
行是多余的。 MATLAB 必须花时间评估日期字符串,然后……什么都没有。您不将输出保存到变量,也不显示它(您用分号抑制了它)。
长话短说:绘图时使用 datenum()
值,并使用 datetick()
使轴标签正确。
我有来自 Excel 中 xlxs 文件的数据集,我必须将其导入 MATLAB。问题是每当我导入数据时,时间总是以小数形式出现。
所以在这里,xlxs文件中的数据显示格式为HH:MM:SS:
这是在 MATLAB 的导入助手中的样子
我要为它生成折线图,它是这样的:
这是我用来生成绘图的示例代码,其中我希望时间不以十进制形式显示。
datestr(Time,'HH:MM:SS');
title ('Particle Measurement for 02-20-2020 @ UPD')
plot(Time,PM10)
xlabel('Time')
ylabel('Particle Measurement')
hold on
plot(Time,PM1)
hold on
plot(Time,PM25)
MATLAB 中的时间 datenum()
values, which are decimal days since 0 Jan 0000. So the things you see are correct times. You can use datestr(Time,'HH:mm:ss')
to get a string for the time, and datetick('x','HH:mm')
以小时为单位获取轴上的刻度线。
代码中的 datestr(Time,'HH:MM:SS');
行是多余的。 MATLAB 必须花时间评估日期字符串,然后……什么都没有。您不将输出保存到变量,也不显示它(您用分号抑制了它)。
长话短说:绘图时使用 datenum()
值,并使用 datetick()
使轴标签正确。