フィルターのクリア

How select/crop geographic region on the basis of lat/lon values?

3 ビュー (過去 30 日間)
Kamran Afroz
Kamran Afroz 2023 年 7 月 7 日
編集済み: Pranavkumar Mallela 2023 年 7 月 27 日
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?

採用された回答

Pranavkumar Mallela
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
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!
Kamran Afroz
Kamran Afroz 2023 年 7 月 8 日
Hi Pranav,
Thank you for your time and help!
It worked.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEarth, Ocean, and Atmospheric Sciences についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by