Hi, I wrote the following script to extract data from my .nc file. The data is for the QIRRIG variable. Time is monthly, over 37 months. Location is a specified grid square. So what i need is 37 numbers corresponding to each month. But I am only getting summaries. Please help!
close all
ncid = netcdf.open('IRAM_2000.nc','NC_NOWRITE');
lat = netcdf.getVar(ncid,0);
whos lat
lon = netcdf.getVar(ncid,1);
whos lon
from_date = '2007-01-16'; to_date = '2010-01-16';
time = netcdf.getVar(ncid,2);
whos time
QIRRIG = netcdf.getVar(ncid,3); %var3 QIRRIG 1081x days
whos QIRRIG
time_datenum = time / 365 + datenum('0-12-31 00:00:00');
date_match = time_datenum >= datenum('2007-01-16') && time_datenum <= datenum('2010-01-16');
selected_QIRRIG = QIRRIG(:, :, date_match);
latlim = [5 30]; %5N 30S
lonlim = [65 95]; %65W 95W

 채택된 답변

KSSV
KSSV 2018년 10월 10일

1 개 추천

YOu need not use such complex functions..have a look on functions ncread, ncdisp and ncinfo. ncread will give you the variable you wanted.
iwant = ncread(myncfile,'QIRRIG') ;

댓글 수: 8

aine gormley
aine gormley 2018년 10월 10일
Hi thanks for your reply. But with this I get over 5000 numbers and it doesn't specify which are attributed to the dates and location that I want
aine gormley
aine gormley 2018년 10월 10일
I guess it is 4 dimensional? can you help?
KSSV
KSSV 2018년 10월 10일
You have an option of specifying the indices...read about the function..
aine gormley
aine gormley 2018년 10월 10일
do u mean array indexing?
KSSV
KSSV 2018년 10월 10일
Yes.....if not attach the file..and required info..will give you the code..:)
KSSV
KSSV 2018년 10월 11일
I suggest you to upload nc file.....a google drive link will do.
KSSV
KSSV 2018년 10월 11일
ncfile = 'IRAM_2000.nc' ;
lon = ncread(ncfile,'lon') ;
lat = ncread(ncfile,'lat') ;
Q = ncread(ncfile,'QIRRIG') ;
dx = 1. ; % can be varied, data is with resolution 1.25
dy = 0.5 ; % can be varied, data is with resolution 0.944
xi = 65:dx:95 ;
yi = 5:dy:30 ;
[X,Y] = meshgrid(lon,lat) ;
[Xi,Yi] = meshgrid(xi,yi) ;
Qi = interp2(X,Y,Q',Xi,Yi)' ;
figure(1)
pcolor(X,Y,Q') ; shading interp ; colorbar
figure(2)
pcolor(Xi,Yi,Qi') ; shading interp ; colorbar
KSSV
KSSV 2018년 10월 11일
In the file you attached the variables were lon nd lat. May be you have changed a file..and variables are written with different name. Check that with ncdisp and write the proper variable names.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 10월 10일

댓글:

2018년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by