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

70 vues (au cours des 30 derniers jours)
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya le 29 Avr 2016
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 commentaires
Walter Roberson
Walter Roberson le 30 Avr 2016
Nothing was attached
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya le 4 Mai 2016
Sir file is attached.

Connectez-vous pour commenter.

Réponses (3)

KSSV
KSSV le 4 Mai 2016
Modifié(e) : KSSV le 4 Mai 2016
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 commentaire
Muhammad Usman Saleem
Muhammad Usman Saleem le 25 Fév 2017
@KSSV dear, will you tell me how can i get data along the complete polygon ?

Connectez-vous pour commenter.


Jitesh Dadich
Jitesh Dadich le 9 Avr 2019
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 commentaires
KSSV
KSSV le 9 Avr 2019
Read about inpolygon.
ANKUR KUMAR
ANKUR KUMAR le 9 Mai 2019
@Jitesh Refer to my answer.

Connectez-vous pour commenter.


ANKUR KUMAR
ANKUR KUMAR le 9 Mai 2019
Modifié(e) : ANKUR KUMAR le 9 Mai 2019
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 commentaires
Saumya Singh
Saumya Singh le 20 Juil 2021
here is the shapefile
Suraj
Suraj le 13 Juin 2023
hi saumya did u find the solution while using the maskregion!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by