MATLAB Answers


Extract data by shapefile

Asked by Tanmoyee Bhattacharya on 29 Apr 2016
Latest activity Commented on by ANKUR KUMAR on 9 May 2019
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.


Sir files are attached.
Nothing was attached

Sign in to comment.

3 Answers

Answer by KSSV
on 4 May 2016
Edited by KSSV
on 4 May 2016

clc; clear all ;
file = '' ;
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) ;
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 Comment

@KSSV dear, will you tell me how can i get data along the complete polygon ?

Sign in to comment.

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....


and can we save the output in .nc format file..?
on 9 Apr 2019
Read about inpolygon.
@Jitesh Refer to my answer.

Sign in to comment.

Answer by ANKUR KUMAR on 9 May 2019
Edited by ANKUR KUMAR on 9 May 2019

You can use maskregion function, which mask out the data as per your shapefile.
Example you can refer to for your convenience
For cropping the data, you can use cropregion.


Sign in to comment.