Plot data from netcdf file

34 ビュー (過去 30 日間)
Jonas Damsbo
Jonas Damsbo 2018 年 9 月 24 日
編集済み: suchitra rani 2019 年 8 月 9 日
Hi
I'm having trouble plotting my netcdf file. I use pcolor, but the first time I tried I had noted Z'. This broke it over and said I should use permute I have done that now, now it comes with the error Matrix dimensions must agree. Why?
if true
filename='Januar79.nc'
%Read the header
ncdisp(filename)
%surf_temp
%Open the file in read only mode
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
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,'latitude')
longitude=ncread(filename,'longitude')
Z=ncread(filename,'z')
pcolor(latitude,longitude,permute(Z, [2 1 3]))
load coast
hold on
plot(long,lat,'k','LineWidth',1.5)
plot(long+360,lat,'k','LineWidth',1.5)
end
  1 件のコメント
Jonas Damsbo
Jonas Damsbo 2018 年 9 月 24 日
Thank you really much! It's working for me now. What did you find out?

サインインしてコメントする。

採用された回答

KSSV
KSSV 2018 年 9 月 24 日
編集済み: KSSV 2018 年 9 月 24 日
ncfile = 'C:\Users\srinivas\Downloads\Januar79.nc' ;
lon = ncread(ncfile,'longitude') ; nx = length(lon) ;
lat = ncread(ncfile,'latitude') ; ny = length(lat) ;
time = ncread(ncfile,'time') ;
for i = 1:length(time)
z = ncread(ncfile,'z',[1 1 i],[nx ny 1]) ;
pcolor(lon,lat,z') ;
shading interp
drawnow
end
  5 件のコメント
KSSV
KSSV 2018 年 9 月 24 日
Edited the answer.....check it.
suchitra rani
suchitra rani 2019 年 8 月 9 日
編集済み: suchitra rani 2019 年 8 月 9 日
what is z in the above code and how can i get the coast data to plot the variable.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by