在 Matlab 中将秒数更改为 UTC
Changing seconds to UTC in Matlab
我在 Matlab 中绘制来自 netcdf 文件的数据,x 轴应该以 UTC 秒为单位。绘图后,我似乎无法弄清楚如何将其更改为 HH:MM:SS 格式。this is an example as you can see on the x-axis of what is happening
我尝试了不同的方法,例如:
time=datenum(x,'HH:MM:SS')
但它们不起作用。
这是我正在尝试做的更好的例子:所以这次飞行的数据是在 2010 年 9 月 10 日拍摄的,数据记录在 "seconds starting at 09:00:00",这是我的代码:
%time
x = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'Time')));
%altitude
y_alt = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'GGALT')));
%temperature
y_t = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'ATX')));
%dew point
y_dp = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'DPXC')));
%vertical wind speed
y_vws = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'WIC')));
%horizontal wind speed
y_hws = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'WSC')));
%liquid water content
y_lwc = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'PLWCC')));
%ice water content
y_iwc = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'PLWC1DC_LMI')));
figure
plot(x,y_alt, 'r')
ylim([0 15000])
title({'Altitude vs Time RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Altitude (meters)');
figure
plot(x,y_t,'b',x,y_dp,'r')
ylim([-100 50])
title({'Temperature and Dew Point RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Temperature (C)');
legend('Temperature', 'Dew Point');
figure
plot(x,y_vws,'b',x,y_hws, 'm')
ylim([-5 11])
xlim([0 20500])
title({'Wind Speed RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Wind Speed (m/s)');
legend('Vertical Wind Speed', 'Horizontal Wind Speed');
figure
plot(x,y_lwc, 'm',x,y_iwc,'b')
ylim([-1 11])
title({'Liquid/Ice Water Content RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('H2O Content (g/m^3)');
legend('Liquid Water Content', 'Ice Water Content');
因此存在的秒数范围为 0-19920。所以我想从 2010 年 9 月 10 日 09:00:00 开始,到 2010 年 9 月 10 日 15:32:00 结束。出于某种原因,我无法让基准的东西为我工作。
如果你的x轴变量是以秒为单位,先除以86400
换算成一天的单位,然后应用datetick
使用所需的日期格式。
这是一个例子
x = 0:10:34e3; % x axis in seconds
y = cumsum(randn(size(x))); % example y values
plot(x/86400, y) % plot with x in days, not in seconds
datetick('x', 'HH:MM:SS') % set date ticks in x axis
grid on % optionally add grid
我在 Matlab 中绘制来自 netcdf 文件的数据,x 轴应该以 UTC 秒为单位。绘图后,我似乎无法弄清楚如何将其更改为 HH:MM:SS 格式。this is an example as you can see on the x-axis of what is happening 我尝试了不同的方法,例如:
time=datenum(x,'HH:MM:SS')
但它们不起作用。 这是我正在尝试做的更好的例子:所以这次飞行的数据是在 2010 年 9 月 10 日拍摄的,数据记录在 "seconds starting at 09:00:00",这是我的代码:
%time
x = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'Time')));
%altitude
y_alt = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'GGALT')));
%temperature
y_t = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'ATX')));
%dew point
y_dp = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'DPXC')));
%vertical wind speed
y_vws = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'WIC')));
%horizontal wind speed
y_hws = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'WSC')));
%liquid water content
y_lwc = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'PLWCC')));
%ice water content
y_iwc = double(netcdf.getVar(ncid,netcdf.inqVarID(ncid,'PLWC1DC_LMI')));
figure
plot(x,y_alt, 'r')
ylim([0 15000])
title({'Altitude vs Time RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Altitude (meters)');
figure
plot(x,y_t,'b',x,y_dp,'r')
ylim([-100 50])
title({'Temperature and Dew Point RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Temperature (C)');
legend('Temperature', 'Dew Point');
figure
plot(x,y_vws,'b',x,y_hws, 'm')
ylim([-5 11])
xlim([0 20500])
title({'Wind Speed RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('Wind Speed (m/s)');
legend('Vertical Wind Speed', 'Horizontal Wind Speed');
figure
plot(x,y_lwc, 'm',x,y_iwc,'b')
ylim([-1 11])
title({'Liquid/Ice Water Content RF14'}, 'fontweight', 'bold', 'fontsize', 12);
xlabel('UTC (seconds)');
ylabel('H2O Content (g/m^3)');
legend('Liquid Water Content', 'Ice Water Content');
因此存在的秒数范围为 0-19920。所以我想从 2010 年 9 月 10 日 09:00:00 开始,到 2010 年 9 月 10 日 15:32:00 结束。出于某种原因,我无法让基准的东西为我工作。
如果你的x轴变量是以秒为单位,先除以86400
换算成一天的单位,然后应用datetick
使用所需的日期格式。
这是一个例子
x = 0:10:34e3; % x axis in seconds
y = cumsum(randn(size(x))); % example y values
plot(x/86400, y) % plot with x in days, not in seconds
datetick('x', 'HH:MM:SS') % set date ticks in x axis
grid on % optionally add grid