|
发表于 2023-4-29 11:33:24
|
显示全部楼层
本楼为最佳答案
根据你提供的代码和nc描述信息,可以看出数据中的时间变量time的范围是从1297320到1954776,表示从1800年到2019年的小时数。因此,可以通过以下代码来获取数据的时间范围并限制在1948年以后的数据中:
- time_units = ncreadatt(filename, 'time', 'units');
- hour_str = regexp(time_units, '\d+', 'match');
- time_hours = str2double(hour_str{1}) / 24;
- start_year = str2double(regexp(time_units, '\d{4}', 'match'));
- start_time = (datenum(1948,1,1) - datenum(start_year,1,1)) * 365 * time_hours + 1;
- end_time = length(time);
- if time(end_time) > datenum(2019,12,31)*24 % 防止超出时间范围
- end_time = find(time < datenum(2019,12,31)*24, 1, 'last');
- end
- time = time(start_time:end_time);
- air = air(:, :, start_time:end_time);
复制代码
这里使用了MATLAB中的datenum函数来将日期转换为从公元0年1月1日到该日期的天数,从而可以计算出从1800年到1948年的小时数,然后再根据时间范围限制数据的选择。 |
|