How to extract data from nc file by using shape file in MATLAB

조회 수: 70 (최근 30일)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2016년 4월 29일
편집: MathWorks Support Team 2023년 7월 11일
How to extract data from nc file by using shape file in matlab. I am sending a sample .nc file of resolution 1*1 degree and shapefile of India.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

답변 (3개)

KSSV
KSSV 2016년 5월 4일
편집: KSSV 2016년 5월 4일
clc; clear all ;
file = 'cpc_rfe_v2.0_sa_dly.bin.20020101.nc' ;
lon = ncread(file,'lon') ;
lat = ncread(file,'lat') ;
RF = ncread(file,'RF') ;
%
path = [pwd filesep 'India State wise with telangana' filesep 'india27-11.shp'] ;
S = shaperead(path) ;
n = length(S) ;
pcolor(lon,lat,RF') ; shading interp ;
hold on
for i = 1%:n
x = S(i).X ; y = S(i).Y ;
rfi = interp2(lon,lat,RF',x,y) ;
end
Your next question is: 'I want data along the polygon, not along the boundary'. It is a project work and you expect everything online?
  댓글 수: 1
Muhammad Usman Saleem
Muhammad Usman Saleem 2017년 2월 25일
@KSSV dear, will you tell me how can i get data along the complete polygon ?

댓글을 달려면 로그인하십시오.


Jitesh Dadich
Jitesh Dadich 2019년 4월 9일
this really helped me....
Dear @KSSV, what if the time is also given in the nc file i.e. nc data are in 3D...then how will we extract the data from .nc file according to given shapefile....
  댓글 수: 3
KSSV
KSSV 2019년 4월 9일
Read about inpolygon.
ANKUR KUMAR
ANKUR KUMAR 2019년 5월 9일
@Jitesh Refer to my answer.

댓글을 달려면 로그인하십시오.


ANKUR KUMAR
ANKUR KUMAR 2019년 5월 9일
편집: ANKUR KUMAR 2019년 5월 9일
You can use maskregion function, which mask out the data as per your shapefile.
Example you can refer to for your convenience
W=shaperead('us_states.shp');
[data_cropped]=maskregion(lon,lat,data,W);
contourf(lon,lat,nanmean(data_cropped,3)','linecolor','none')
fig1.jpg
For cropping the data, you can use cropregion.
  댓글 수: 5
Suraj
Suraj 2023년 6월 13일
hi saumya did u find the solution while using the maskregion!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by