How select/crop geographic region on the basis of lat/lon values?
5 次查看(过去 30 天)
显示 更早的评论
I want to select/crop region on the basis of lat/lon.
I have geographical data with dimensions of lat,lon and time from which I want to crop a region using four lat/lon(e.g. LAT: 13,18; LON: 73,76) points like a rectangle.
I have attached my sample data for reference.
Can anyone help me with this problem?
0 个评论
采纳的回答
Pranavkumar Mallela
2023-7-7
编辑:Pranavkumar Mallela
2023-7-27
Hi,
As per my understanding, you are trying to crop a region that is part of the sample data, which includes the 'rf' value over a 100x100 area and 48 time instances.
First use 'ncread' to read the 'rf' variable from the above attached file in the following way:
rf = ncread("test.nc", 'rf');
The variable 'rf' is a 100x100x48 double matrix. To crop a certain geographical region at a given time 't', you can use the following code:
cropped_region = rf(13:18, 73:76, t); % at a given time 't'
For more information regarding selection of data from a matrix, you can refer the following documentation: https://www.mathworks.com/help/matlab/math/array-indexing.html
Hope this helps! Thanks!
3 个评论
Pranavkumar Mallela
2023-7-7
编辑:Pranavkumar Mallela
2023-7-27
Hey, thanks for clarifying that.
You can utilize the 'find' function to find the indices of the required latitude and longitude ranges.
The code is as follows:
lat = [1 2 3 4 5 6 7 8 9 10]; % assume this is your latitude data
lon = [1 2 3 4 5 6 7 8 9 10]; % assume this is your longitude data
% Set the required limits here
req_lat_ll = 13; req_lat_ul = 18;
req_lon_ll = 73; req_lon_ul = 76;
lat_ll = find(lat <= req_lat_ll ,1,'last'); % ll = lower limit
lat_ul = find(lat >= req_lat_ul,1,'first'); % ul = upper limit
lon_ll = find(lon <= req_lon_ll ,1,'last');
lon_ul = find(lon >= req_lon_ul,1,'first');
cropped_region = rf(lat_ll:lat_ul, lon_ll:lon_ul, t); % at a given time 't'
Now you should be able to access rainfall using latitude and longitude ranges.
For more information regarding the 'find' function, please refer to this documentation:
Thanks! Hope this helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!