I have hourly surface temperature data from the model output. The data is a 3D matrix with a size of 303×185×1176 (lon×lat×time). Now, I have to create two matrixes from the existing data. One matrix will be for only daylight hours (6.30 AM-6.30 PM) and another matrix will be for only nighttime hours (6.30 PM-5.30 AM). Since the timestep of the model output is in UTC, I have to add 5.30 with the model hours to get the IST (Indian standard time). Thus, in my case, for the first day, daylight hours start from the timesteps 1 to 13, and nighttime hours start from the timesteps 13 to 24. So, we have to add 24 hours to the above timestep ranges to get the daytime and nighttime hours for the next day. Similarly, for the day after the next day, we have to add 48 hours with the first timestep ranges for getting the daytime and nighttime hours, and so on. I tried with the following MATLAB code:
num_hours_per_day = 24;
num_days = size(ST_data, 3) / num_hours_per_day;
daytime_start = 1; % Initial daytime start timestep
nighttime_start = 13; % Initial nighttime start timestep
num_hours = size(ST_data, 3);
% Initialize daytime and nighttime matrices
daytime_matrix = [];
nighttime_matrix = [];
% Loop through each day
for day = 1:num_days
% Calculate indices for daytime and nighttime hours
daytime_indices = daytime_start:daytime_start+12; % Daytime hours (01:00 to 13:00)
nighttime_indices = nighttime_start:nighttime_start+11; % Nighttime hours (14:00 to 24:00)
% Update daytime and nighttime matrices
daytime_matrix(:,:,daytime_indices) = ST_data(:,:,daytime_indices);
nighttime_matrix(:,:,nighttime_indices) = ST_data(:,:,nighttime_indices);
% Update start timesteps for the next day
daytime_start = daytime_start + 24;
nighttime_start = nighttime_start + 24;
end
But, I think that my code is incorrect. Because, after running the code, the size of daytime_matrix is 303×185×1165 and nighttime_matrix is 303×185×1176. If I am separating the total hours into daytime and nighttime, then the size of the third dimension of each matrix should be almost half of the total timestep.
For your reference, I am giving the lines that are printed after giving the command 'whos ST_data':
>> whos ST_data
Name Size Bytes Class Attributes
ST_data 303x185x1176 527365440 double
Also, the following lines are printed when I run 'ST_data(1, 1, 1:3)' in the command window:
>> ST_data(1, 1, 1:3)
ans(:,:,1) =
15.2422
ans(:,:,2) =
15.0156
ans(:,:,3) =
14.7905
Note that the values of the surface temperature are in degrees Celsius. So, can anyone please help me to create the correct MATLAB code according to the above calculation? That will be very helpful for me. Thank you for your time and consideration.
With regards,
Ankan