Hey @Nikhil Sumer, to extract daily rainfall data for a specific set of coordinates from your grid data, you can follow these steps in MATLAB. This process involves reading the data from your Excel file, identifying the correct grid cell that corresponds to the desired coordinates, and then extracting the data for that cell across all days.
% Define the coordinates of interest
targetLatitude = 23.5; % Example latitude
targetLongitude = 77.0; % Example longitude
% Load the grid data from Excel
filename = 'rainfall_data_2013.xlsx';
sheet = 1; % Assuming all data is in the first sheet
data = readmatrix(filename, 'Sheet', sheet);
% Define grid resolution and boundaries
% These should match your dataset's specifics
latRange = [6.0, 37.0]; % Example latitude range for India
lonRange = [68.0, 97.0]; % Example longitude range for India
numLatCells = 31; % Number of latitude grid cells
numLonCells = 29; % Number of longitude grid cells
% Calculate the size of each grid cell
latCellSize = (latRange(2) - latRange(1)) / numLatCells;
lonCellSize = (lonRange(2) - lonRange(1)) / numLonCells;
% Find the index of the target grid cell
latIndex = floor((targetLatitude - latRange(1)) / latCellSize) + 1;
lonIndex = floor((targetLongitude - lonRange(1)) / lonCellSize) + 1;
% Initialize a vector to store extracted data
extractedData = [];
% Loop through each day's data
numDays = size(data, 1) / (numLatCells * numLonCells); % Assuming data is stacked
for day = 1:numDays
% Extract the grid data for the current day
dayData = data((day-1)*numLatCells*numLonCells+1 : day*numLatCells*numLonCells, :);
% Reshape the day's data into a 2D grid
dayGrid = reshape(dayData, numLatCells, numLonCells);
% Extract the data for the target coordinates
value = dayGrid(latIndex, lonIndex);
% Check if the value is valid (not null)
if value ~= -999
extractedData(end+1) = value; % Append the value to the extracted data
else
extractedData(end+1) = NaN; % Use NaN for null values
end
end
% Display the extracted data
disp('Extracted Rainfall Data for Target Coordinates:');
disp(extractedData);