how to clip a domain data from global data?
Ältere Kommentare anzeigen
I am trying to clip South Asia domain (19.25°E-116.25°E,-15.75°S-45.75°N) from a global dataset with 0.5 degree resolution.
Here is the code i am using:
global_data = load('global_data.mat');
% Define the latitude and longitude boundaries
lat_start = -15.75;
lat_end = 45.75;
lon_start = 19.25;
lon_end = 116.25;
% Define the resolution
resolution = 0.5;
% Calculate the indices for cropping
lat_indices = floor((lat_start + 90) / resolution) + 1 : floor((lat_end + 90) / resolution) + 1;
lon_indices = floor((lon_start + 180) / resolution) + 1 : floor((lon_end + 180) / resolution) + 1;
% Crop the global data
cropped_data = global_data(lat_indices, lon_indices, :);
% Display the size of the cropped data
disp(size(cropped_data));
Can someone help me with this?
Thank you.
Antworten (2)
Here are two ways to get it with two small corrections in your code:
Way - 1. Just use load() without variable name assigning, because the variable name is the same:
load('global_data.mat');
% Define the latitude and longitude boundaries
lat_start = -15.75;
lat_end = 45.75;
lon_start = 19.25;
lon_end = 116.25;
% Define the resolution
resolution = 0.5;
% Calculate the indices for cropping
lat_indices = floor((lat_start + 90) / resolution) + 1 : floor((lat_end + 90) / resolution) + 1;
lon_indices = floor((lon_start + 180) / resolution) + 1 : floor((lon_end + 180) / resolution) + 1;
% Crop the global data
cropped_data = global_data(lat_indices, lon_indices, :);
% Display the size of the cropped data
disp(size(cropped_data));
Way - 2. Read data from Stucture variable, e.g.: global_data.global_data
global_data = load('global_data.mat');
global_data = load('global_data.mat');
% Define the latitude and longitude boundaries
lat_start = -15.75;
lat_end = 45.75;
lon_start = 19.25;
lon_end = 116.25;
% Define the resolution
resolution = 0.5;
% Calculate the indices for cropping
lat_indices = floor((lat_start + 90) / resolution) + 1 : floor((lat_end + 90) / resolution) + 1;
lon_indices = floor((lon_start + 180) / resolution) + 1 : floor((lon_end + 180) / resolution) + 1;
% Crop the global data
cropped_data = global_data.global_data(lat_indices, lon_indices, :);
% Display the size of the cropped data
disp(size(cropped_data));
1 Kommentar
Vidushi Koliyan
am 28 Jun. 2023
Bearbeitet: Vidushi Koliyan
am 28 Jun. 2023
If understood your question correctly, what you want is to display your cropped data, right?
If so, here is how it can be done:
load('global_data.mat');
% Define the latitude and longitude boundaries
lat_start = -15.75;
lat_end = 45.75;
lon_start = 19.25;
lon_end = 116.25;
% Define the resolution
resolution = 0.5;
% Calculate the indices for cropping
lat_indices = floor((lat_start + 90) / resolution) + 1 : floor((lat_end + 90) / resolution) + 1;
lon_indices = floor((lon_start + 180) / resolution) + 1 : floor((lon_end + 180) / resolution) + 1;
% Crop the global data
cropped_data = global_data(lat_indices, lon_indices, :);
% Display the size of the cropped data
disp(size(cropped_data));
figure
imagesc(cropped_data(:,:,1)) % Cropped data set
figure
imagesc(global_data(:,:,1)) % Whole data set
In order to create the two image as you mentioned, you need to specify the corodinates (indices) as in this cropped one.
1 Kommentar
Vidushi Koliyan
am 28 Jun. 2023
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

