Plot variables (total could cover) from Netcdf file

5 ビュー (過去 30 日間)
hayat belherkat
hayat belherkat 2020 年 10 月 4 日
コメント済み: hayat belherkat 2020 年 10 月 4 日
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

採用された回答

KSSV
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
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)
hayat belherkat
hayat belherkat 2020 年 10 月 4 日
is that mean i have to make value of indices positive:
>> tcdc_ij = squeeze(tcdc(i,j,:));
Index in position 2 is invalid. Array indices must
be positive integers or logical values.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by