- Extract the size of data using “[lon, lat, time] = size(climateData);”
- You can reshape the data as per your requirement with the following command: “reshapedData = reshape(climateData, [[lon,lat], time]);”. As the data I created was already in the format 1x2x12, the size of the “reshapedData” will remain same.
- Convert the time vector data to datetime format using: “timeVector = datetime(timeVector);”
- Now you can use this time data to extract unique years or any other information. If you wish to extract unique years from the data you can use: “years = unique(year(timeVector));”
- To plot the created time series data use: “scatter3(x_lon,y_lat, timeVector)”. Where “x_lon” and “y_lat” contains the longitudes and latitudes respectively.
Create timeseries with 3d climate data
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I have 3d climate data in the form lonxlatxtime. I would like to create a timeseries for these data for every year, but have no idea how to do this since I am new to Matlab. Can someone please assist?
Thank you
0 个评论
回答(1 个)
Ayush
2023-10-5
Hi Aarde,
I understand that you want to create time series of the 3D data points which is in the form longitude x latitude x time.
Since the data was not provided, I generated my own data points, which is of the dimension “1x2x12”. Meaning that there will be 1 row and 2 columns where first column will contain the data of the longitude and the second column will contain the data of the latitude and there are total of 12 years.
I randomly generated data of longitude and latitude using the “randi” command, keeping the range from 0 to 180 (representing degrees).
Considering that the data is ready with us, following steps can be used to display the data in timeseries:
Final code snippet is given below:
%% Data Generation
lon = 1; % Number of longitudes
lat = 2; % Number of latitudes
time = 12; % Number of time steps
% Generate random climate data
climateData = randi([0 180],lon, lat, time);
% Display the size of the climate data
disp(size(climateData));
% Generate a random time vector
numTimeSteps = 12; % Number of time steps
% Generate random values for year, month, day, hour, minute, and second
yearValues = randi([2000, 2021], numTimeSteps, 1); % Random years between 2000 and 2021
monthValues = randi([1, 12], numTimeSteps, 1); % Random months
dayValues = randi([1, 28], numTimeSteps, 1); % Random days
hourValues = randi([0, 23], numTimeSteps, 1); % Random hours
minuteValues = randi([0, 59], numTimeSteps, 1); % Random minutes
secondValues = randi([0, 59], numTimeSteps, 1); % Random seconds
% Create the random time vector
timeVector = datetime(yearValues, monthValues, dayValues, hourValues, minuteValues, secondValues);
% Display the time vector
disp(timeVector);
%% Time Series Conversion
[lon, lat, time] = size(climateData);
reshapedData = reshape(climateData, [[lon,lat], time]);
timeVector = datetime(timeVector);
years = unique(year(timeVector));
disp("Unique year: " + years)
%% Data Plotting
x_lon = squeeze(reshapedData(:,1,:));
y_lat = squeeze(reshapedData(:,2,:));
scatter3(x_lon,y_lat, timeVector)
1 个评论
Ronald
2024-4-8
Hi Ayush, could you modify this code so it can be used to reshape a 3D timeseries matrix(lon,lat,time) from daily to monthly? or from monthly to annual?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Climate Science and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!