how to clip a domain data from global data?
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Sulaymon Eshkabilov
2023-6-28
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));
Sulaymon Eshkabilov
2023-6-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!