Plot variables (total could cover) from Netcdf file

1 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 4 Oct 2020
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 Comments
KSSV
KSSV on 4 Oct 2020
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 on 4 Oct 2020
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Weather and Atmospheric Science in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!