How can I get the XMinorTick as a numerical value?

조회 수: 9 (최근 30일)
Soroush Asarzadeh
Soroush Asarzadeh 2016년 2월 26일
편집: Walter Roberson 2016년 2월 27일
Hi, I want to know the minor step size of my x-axis. The XTickMode is set to auto and I know that XMinorTick={on/off}, but I want to calculate the numerical value of minor step size just like: XTick(2)-XTick(1) for example:
XTick = [0:2:10]
MajorStep = XTick(2) - XTick(1); % 2-0=2
if MajorStep(2) - MajorStep(1) > 1
set(gca,'XMinorGrid','on','XMinorTick','on')
end
% now I want to calculate the minor step size
% MinorStep = XMinorTick(2) - XMinorTick(1) this obviously is not going to work but I want the numerical answer of it
Can anybody help me please?
  댓글 수: 1
dpb
dpb 2016년 2월 26일
편집: dpb 2016년 2월 27일
Don't think so...the minor ticks values are hidden in HG with no way to access them. I suppose one could save the figure as an image and find the pixels that are set and deduce it from that but is pretty tough.
The best think one could do would be to try to work out heuristically how many minor ticks there will be based on the major tick spacing; by default it starts with five, if you increase the spacing as you did above in the example there are 10; if decrease by spacing at 0.5 for major then there's only 2. (These are divisions between major divisions, not the intermediate ticks). But I don't think there's any way to retrieve what is done internally.
ADDENDUM Oh, in digging following up Kevin's response I see there is a recent enhancement...but must have R2015b or later to gain access to it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kevin Claytor
Kevin Claytor 2016년 2월 26일
with ax = your axes object
ax.XAxis.MinorTickValues
  댓글 수: 2
Soroush Asarzadeh
Soroush Asarzadeh 2016년 2월 27일
with this code
ax=gca;
MinorStep=ax.XAxis.MinorTickValues;
I get the following error message: No appropriate method, property, or field XAxis for class matlab.graphics.axis.Axes.
dpb
dpb 2016년 2월 27일
편집: Walter Roberson 2016년 2월 27일
Must have R2015b...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by