MATLAB: Plot variables (total could cover) from Netcdf file

Data Acquisition Toolboxjonas damsbokssv

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

Best Answer

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