MATLAB: How to specify the X and Y ticklable

xticklable

Hi, so I'm trying to specify the Xticklable and Yticklable on a contourf. Unfortunately when I give the vector that I want to see, matlab repeat those lables on the axes. This is the code I'm using:
vec=[-180 -36 0 36 180]
for i=1:3
figure(1)
subplot(1,3,i)
if i==1
contourf(nzro_mean1)
elseif i==2
contourf(nzro_mean2)
elseif i==3
contourf(nzro_mean3)
end
axis square
set(gca,'XTickLabel',{vec})
set(gca,'YTickLabel',{vec})
title(['Especie ',num2str(i)])
colorbar('southoutside')
end
and the images below is how appers. Does anybody knows what is happening and how can I solve this? note: nzro_mean1, 2 and 3 is a matrix 5×5

Best Answer

Replace your current set calls:
set(gca,'XTickLabel',{vec})
set(gca,'YTickLabel',{vec})
with these assignments:
xt = get(gca, 'XTick');
xtv = linspace(min(xt), max(xt), numel(vec));
yt = get(gca, 'YTick');
ytv = linspace(min(yt), max(yt), numel(vec));
set(gca, 'XTick',xtv, 'XTickLabel',vec, 'YTick',ytv, 'YTickLabel',vec)
That should work.