how to combined monthly data in sequence?
4 次查看(过去 30 天)
显示 更早的评论
hello all,
I have a time series data for 10 year (lat X lon X 120). For taking monthly mean of every jan, feb.... dec, I have separated jan to dec data
jan = data(:,:,[1:12:10]);
feb = data(:,:,[2:12:10]);
mar = data(:,:,[3:12:10]);
aprl = data(:,:,[4:12:10]);...........
Then I have taken mean,
jan_mean = mean(jan(:,:,1:10),3); feb_mean = mean(feb(:,:,1:10),3); .......................................................dec_mean = mean(dec(:,:,1:10),3);
For calculation of anomaly, Anom_jan = jan - jan_mean, Anom_feb = feb - feb_mean......................
Now, I want to combined all these Anom timeseries in seuence (lat X lon X 120).
how to merge theses timeseries in sequece of jan to dec of ever year?
0 个评论
回答(1 个)
Manikanta Aditya
2024-7-9
编辑:Manikanta Aditya
2024-7-9
You can concatenate the anomaly time series data for each month along the third dimension using the cat function in MATLAB.
Here’s how you can do it:
Anom_combined = cat(3, Anom_jan, Anom_feb, Anom_mar, Anom_apr, Anom_may, Anom_jun, Anom_jul, Anom_aug, Anom_sep, Anom_oct, Anom_nov, Anom_dec);
This will create a new 3D matrix Anom_combined where the third dimension is the time series data for each month from January to December for every year. The size of Anom_combined will be (lat X lon X 120), same as your original data. Replace with your actual varible names.
I hope this clarifies
2 个评论
Manikanta Aditya
2024-7-10
I understand. You want to concatenate the anomalies in a way that represents the monthly sequence for each year, rather than all of the same months together.
Here is how you can do it:
% Assuming Anom_jan, Anom_feb, ..., Anom_dec are already calculated
% Preallocate the combined anomaly matrix
Anom_combined = zeros(size(Anom_jan, 1), size(Anom_jan, 2), 120);
% Number of years
num_years = 10;
% Loop through each year and interleave the monthly data
for year = 1:num_years
for month = 1:12
% Determine the correct index in the combined matrix
idx = (year - 1) * 12 + month;
% Assign the monthly anomaly to the correct position
switch month
case 1
Anom_combined(:, :, idx) = Anom_jan(:, :, year);
case 2
Anom_combined(:, :, idx) = Anom_feb(:, :, year);
case 3
Anom_combined(:, :, idx) = Anom_mar(:, :, year);
case 4
Anom_combined(:, :, idx) = Anom_apr(:, :, year);
case 5
Anom_combined(:, :, idx) = Anom_may(:, :, year);
case 6
Anom_combined(:, :, idx) = Anom_jun(:, :, year);
case 7
Anom_combined(:, :, idx) = Anom_jul(:, :, year);
case 8
Anom_combined(:, :, idx) = Anom_aug(:, :, year);
case 9
Anom_combined(:, :, idx) = Anom_sep(:, :, year);
case 10
Anom_combined(:, :, idx) = Anom_oct(:, :, year);
case 11
Anom_combined(:, :, idx) = Anom_nov(:, :, year);
case 12
Anom_combined(:, :, idx) = Anom_dec(:, :, year);
end
end
end
Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!