How to plot a Hovmoller diagram in MATLAB? Im trying to create a Hovmoller diagram in MATLAB but I'm very new to programming and have no clue what to do. Im trying to do it for vorticity. Below is the code that I have currently. Any input or advice, would be greatly appreciated.

path(path,'/Users/zoleak/Documents/');
lev_name='700';%mb

disp(strcat('calculating mean fields...',lev_name,'mb'))

file1 = '/Users/zoleak/Documents/Datasets/Patricia/ERAi.T.00.2015.1p5.45N45S.nc';
file2 = '/Users/zoleak/Documents/Datasets/Patricia/ERAi.U.00.2015.1p5.45N45S.nc';
file3 =  '/Users/zoleak/Documents/Datasets/Patricia/ERAi.V.00.2015.1p5.45N45S.nc';
file4 =  '/Users/zoleak/Documents/Datasets/Patricia/ERAi.GEO.00.2015.1p5.45N45S.nc';
file5 =  '/Users/zoleak/Documents/Datasets/Patricia/ERAi.VORT.00.2015.1p5.45N45S.nc';
file6 =  '/Users/zoleak/Documents/Datasets/Patricia/ERAi.PV.00.2015.1p5.45N45S.nc';

%Read files in
lat=ncread(file1,'latitude');
lon=ncread(file1,'longitude');
levels=ncread(file1,'level');
u_data=ncread(file2,'u');
v_data=ncread(file3,'v');
vort_data=ncread(file5,'vo');

%Format Files
x=lon(28:121);
y=lat(1:31);
[nlons,nlats,ntimes]=size(vort_data);
u_data=u_data(28:121,1:31,4,:);
v_data=v_data(28:121,1:31,4,:);
vort_data=vort_data(28:121,1:31,4,:);

u_data=squeeze(squeeze(u_data));
v_data=squeeze(squeeze(v_data));
vort_data=squeeze(squeeze(vort_data));

%%

clf;

lat_avg=mean(vort_data(5:15,:,:),1);     

LONLIMS=[-139.5 -60];
LATLIMS=[0 30];
[lon_plot,lat_plot]=meshgrid(x,y);
proj('mercator','lon',LONLIMS,'lat',LATLIMS);
%m_quiver(lon_plot,lat_plot,u_data(:,:)',v_data(:,:)','LineStyle','-','Color',[0 0 0],'AutoScaleFactor',2);
hold on;
contourf(lon_plot,lat_plot,lat_avg(:,:)','LevelList',[-6e-4:1e-5:6e-4],'LineColor','none')
coast('patch',[1 1 1],'linewi',2);
grid('linewi',0.5,'tickdir','out','linest','none');
set(gca,'FontSize',14);
set(gcf,'Color','white');
hcb=colorbar('eastoutside');
title(['5N-20N,700mb Vorticity']);
set(hcb,'YTick',[-1e-4:1e-5:1e-4])
caxis([-.5e-4 .5e-4])
save_name1=strcat('/Users/zoleak/Documents/figures/HOVMOLLER/PAT_VORT');
print(save_name1,'dpdf'-r600);
Here is an example using contourf. The trick is in sampling the 3D arrays appropriately:

    x=linspace(0,pi,20);
y=linspace(0,pi,10);
t=0:10:120;
[X3d,Y3d,T3d]=meshgrid(x,y,t);
[X2d,T2dx]=meshgrid(x,t);
[Y2d,T2dy]=meshgrid(y,t);

dat3d=7*sin(X3d)+5*cos(Y3d)+T3d/max(T3d(:))+rand(size(X3d));
dat2dx=7*sin(X2d)+5*cos(y(5))+T2dx/max(T2dx(:))+rand(size(X2d)); % at y(5)
dat2dy=7*sin(x(12))+5*cos(Y2d)+T2dy/max(T2dy(:))+rand(size(Y2d));  % at x(12)
%%
figure(1);clf
contourf(X2d,T2dx,dat2dx);
shading flat; colorbar
ylabel('Time (days)')
xlabel('X distance (km)')
%%
figure(2);clf
contourf(Y2d,T2dy,dat2dy);
shading flat; colorbar
ylabel('Time (days)')
xlabel('Y distance (km)')
%%
figure(3);clf
subplot(221)
contourf(squeeze(X3d(5,:,:)),squeeze(T3d(5,:,:)),squeeze(dat3d(5,:,:)));
shading flat; colorbar
ylabel('Time (days)'); xlabel('X distance (km)')
title('Hovmoller at y(5)')
subplot(222)
contourf(squeeze(Y3d(:,12,:)),squeeze(T3d(:,12,:)),squeeze(dat3d(:,12,:)));
shading flat; colorbar
ylabel('Time (days)'); xlabel('Y distance (km)')
title('Hovmoller at x(12)')
subplot(223)
contourf(squeeze(X3d(8,:,:)),squeeze(T3d(8,:,:)),squeeze(dat3d(8,:,:)));
shading flat; colorbar
ylabel('Time (days)'); xlabel('X distance (km)')
title('Hovmoller at y(8)')
subplot(224)
contourf(squeeze(Y3d(:,17,:)),squeeze(T3d(:,17,:)),squeeze(dat3d(:,17,:)));
shading flat; colorbar
ylabel('Time (days)'); xlabel('Y distance (km)')
title('Hovmoller at x(17)')