Monthly RMSE of daily data taken during a whole year

1 次查看(过去 30 天)
I have my data on a table in which the first column has all the daily dates of a year (1-Jan-2014, 2-Jan-2014 ... ) and the second and third column contains values of mean daily temperatures calculated by two methods. I would like to compare this two methods calculating the monthly RMSE of the temperatures given by this two methods. That means that for each month, I would like to calculate the squared difference between the temperatures of each day, then the mean of that difference and finally the square root. Is there any way to select only the daily values of each different month taking into account that they have different number of days ? At the end I would like to obtain the 12 values of RMSE for each month, obtained comparing the daily temperatures of the third column (the true daily mean) and the second column (an approximation of the mean calculated by another method).
Thanks for your time.

回答(1 个)

Ravi
Ravi 2023-10-14
Hi Victor Martinez,
I understand that you are trying to find the RMSE of temperature over every month instead of computing it over the year.
Kindly follow the below steps,
  • Find the month to which a given date belongs to. For this, you can use the “month” function. But the function accepts a datetime object as an argument. Therefore, convert the table date entry into its corresponding datetime object.
month_function = @(dateStr) month(datetime(dateStr, "InputFormat", "dd-MM-yyyy"));
  • Use a for loop to iterate over the month numbers starting from 1 to 12. For each month number, extract the data that corresponds to that month number.
% target month is the current month in iteration
condition = month_function(data.date) == targetMonth;
monthData = data(condition, :);
  • From the extracted data,
  • Compute the difference of second and third columns. The result will be a vector.
  • Square every entry of the vector and sum them up.
  • Apply square root to the result, which is the required RMSE.
  • Concatenate the result to a list containing RMSE values for every month.
For more understanding on the above-mentioned functions, please refer to the following resources.
Hope this helps !

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by