Plot variables (total could cover) from Netcdf file
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello ,
I'm Student and work on my project but , I faced a problem because i am beginner in MATLAB and analyze data netcdf format , i have to plot meteorological variables as a function of time, first i tried to plot it with latitude and longitude but i find error using pcolor and plot . i need help to find the correct script for plotting this variables as a function of 'lon' and 'lat' and also time
this is code i used :
filename='tcdc.nc'
%Read the header
ncdisp(filename)
ncid=netcdf.open(filename,'NOWRITE')
%inspect num of dimensions, variables, attributes, unim
[ndim, nvar, natt, unlim]=netcdf.inq(ncid)
for i=0:nvar-1
[varname, xtype, dimid, natt]=netcdf.inqVar(ncid,i);
if strcmp(varname,'surf_temp')==1
varnumber=i; end
end
[varname, xtype, dimid, natt]=netcdf.inqVar(ncid,varnumber)
%extract info for each dimension
for i=1:length(dimid)
[dimname, dimlength]=netcdf.inqDim(ncid,dimid(1,i))
end
for i=0:nvar-1
[varname, xtype, dimid, natt]=netcdf.inqVar(ncid,i);
if strcmp(varname,'latitude')==1
dimnumber=i
end
end
latitude=ncread(filename,'lat')
longitude=ncread(filename,'lon')
tcdc=ncread(filename,'tcdc')
pcolor(longitude,latitude,tcdc')
Error using '
Transpose on ND array is not defined. Use PERMUTE
instead.
>> hold on
>> plot(longitude,latitude,tcdc)
Error using plot
Vectors must be the same length
thank you
댓글 수: 0
채택된 답변
KSSV
2020년 10월 4일
Your tcdc is a 3D matrix. You can plot only one 2D matrix using pcolor. Follow the below:
pcolor(longitude,latitude,tcdc(:,:,1)') % plot the first matrix
[m,n,p] = size(tcdc) ;
for i = 1:p
pcolor(longitude,latitude,tcdc(:,:,i)')
shading interp
colorbar
drawnow
end
댓글 수: 3
KSSV
2020년 10월 4일
If you know th indices of your required point..you can extract that series and plot.
tcdc_ij = squeeze(tcdc(i,j,:)) ;
plot(time,tcdc_ij)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

