Dear all I found a solution, I just simply delete any string that contains NaN. See updated code below:
figure
H = pcolor(xedges,yedges,Ab);
colormap(cm);
set(H, 'linestyle', 'none');
pos=get(gca,'position'); % get plot position
[rows,cols]=size(Ab); % get cols and rows size
width=pos(3)/(cols-1); % get width and height postions
height =pos(4)/(rows-1);
%create textbox annotations
for i=1:cols-1
for j=rows-1:-1:1;
annotation('textbox',[pos(1)+width*(i-1),pos(2)+height*(j-1),width,height], ...
'string',num2str(Ab(j,i)),'LineStyle','none','HorizontalAlignment','center',...
'FontSize',10,'FontWeight','Bold',...
'VerticalAlignment','middle');
end
end
delete(findall(gcf,'String','NaN')); % delete the annotation
set(gca,'Xlim',[0 30]);
set(gca,'XTick',[0:3:30]);
set(gca,'Ylim',[0 5]);
set(gca,'YTick',[0:1:5]);
set(gca,'FontSize',10,'FontWeight','Bold');
Cheers, Raydo