2014-04-27 2 views
4

MATLAB의 눈금을 눈금과 정렬되도록 배치하려고합니다. 그러나 눈금을 오프셋하는 좋은 방법을 찾을 수 없습니다.MATLAB 축 틱을 반으로 이동합니다.

또한 set(gca,'XTickLabel',1:10)을 실행하면 내 x 눈금 레이블이 1에서 5까지로 끝납니다.

enter image description here

답변

7

당신은 이동 한 후 다시 그들에게 진드기를 이동하지만, 전에 레이블을 얻을 작성해야합니다 :

f = figure(1) 
X = randi(10,10,10); 
surf(X) 
view(0,90) 

ax = gca; 
XTick = get(ax, 'XTick') 
XTickLabel = get(ax, 'XTickLabel') 
set(ax,'XTick',XTick+0.5) 
set(ax,'XTickLabel',XTickLabel) 

YTick = get(ax, 'YTick') 
YTickLabel = get(ax, 'YTickLabel') 
set(ax,'YTick',YTick+0.5) 
set(ax,'YTickLabel',YTickLabel) 

enter image description here


을 또는 당신이 전에 모든 것을 알고있는 경우에, 수동으로 처음부터 수행 :

[N,M] = size(X) 

set(ax,'XTick',0.5+1:N) 
set(ax,'XTickLabel',1:N) 
set(ax,'YTick',0.5+1:M) 
set(ax,'YTickLabel',1:M) 
+0

완벽한 대답을. 감사! –

0

표시된 답변은 서핑이나 메쉬 플롯에서 작동하지만 2 차원 플롯에서 작동하는 솔루션이 필요했습니다. 이 두 축을 생성하여 수행 할 수 있습니다, 하나는 그리드를 표시하고이 스크립트는 다음 그림 표시

xlabels=1:1:10;        %define where we want to see the labels 
xgrid=0.5:1:10.5;        %define where we want to see the grid 

plot(xlabels,xlabels.^2);      %plot a parabola as an example 
set(gca,'xlim',[min(xgrid) max(xgrid)]);  %set axis limits so we can see all the grid lines 
set(gca,'XTickLabel',xlabels);    %print the labels on this axis 

axis2=copyobj(gca,gcf);      %make an identical copy of the current axis and add it to the current figure 
set(axis2,'Color','none');     %make the new axis transparent so we can see the plot 
set(axis2,'xtick',xgrid,'XTickLabel','');  %set the tick marks to the grid, turning off labels 
grid(axis2,'on');        %turn on the grid 

을 다음과 같이 다른 레이블을 표시 :

enter image description here

관련 문제