Discussion on MATLAB Processing of Multidimensional Time Series

Discussion on MATLAB Processing of Multidimensional Time SeriesDiscussion on MATLAB Processing of Multidimensional Time SeriesDiscussion on MATLAB Processing of Multidimensional Time SeriesDiscussion on MATLAB Processing of Multidimensional Time Series

MATLAB Processing

Discussion on Multidimensional Time Series

Author: Li Zhi, Eighth Galaxy

Contact Email: [email protected]

There is a function that can solve the problem, and everyone is welcome to discuss it. This article focuses on how to integrate two time dimensions into one dimension for a four-dimensional dataset (longitude, latitude, month, year) with a spatial range of 10*20 over 30 years on a monthly basis. Additionally, it discusses how to calculate the annual average or total for a three-dimensional dataset (covering leap years and common years) with a spatial range of 10*20 and daily data over 5 years (longitude, latitude, daily data for all years). A brief explanation of these two cases is provided.

Complete CodeDiscussion on MATLAB Processing of Multidimensional Time Series

clc;
clear;
close all;
%% For a spatial range of 10*20, how to integrate two time dimensions into one dimension for a four-dimensional dataset over 30 years on a monthly basis.

R1 = rand([10,20,12,30]);R1size = size(R1);
% Randomly generate a four-dimensional dataset with a spatial range of 10*20 over 30 years on a monthly basis.

R1_3=zeros(10,20,360);% Create a three-dimensional dataset with a spatial range of 10*20 over 360 months.
for i = 1:30% Since there are 30 years, the loop runs from 1 to 30
  idx = (i-1)*12+1:i*12;
  R1_3(:,:,idx) = R1(:,:,:,i);
end
R1_3size = size(R1_3);


%% For a spatial range of 10*20, how to calculate the annual average or total for a three-dimensional dataset with daily data over 5 years (covering leap years and common years)
start_year = 2014;
end_year = 2018;

pre = rand([10,20,1826]);R1size = size(R1);% 365*4+366=1826 days
preyear = zeros(size(pre, 1), size(pre, 2), end_year - start_year + 1);

for year =start_year:end_year
    num_days = 365; % Default to common year
    
    if mod(year, 4) == 0 && (mod(year, 100) ~= 0 || mod(year,400)== 0)
        num_days = 366; % Leap year
    end
    
    pre_1 = pre(:, :, (year - start_year) * num_days + 1 : (year - start_year + 1) * num_days);
    pre_2 = sum(pre_1, 3);% Use sum for total, use mean for average
    preyear(:, :, year - start_year + 1) = pre_2;
end
preyearsize=size(preyear);% preyear is the resulting data

Discussion on MATLAB Processing of Multidimensional Time Series

Backend Response:Eighth Galaxy

Join the group,

Daily data updates for the required articles will be provided in the group.

Discussion on MATLAB Processing of Multidimensional Time Series

Please do not reply with any words other than Eighth Galaxy or other terms.

ShareCollectLikeView

Edited by: myp

Leave a Comment