How Do I Get Exponent Values for Log Axes?

Starting in R2014b, the XTickLabel, YTickLabel, or ZTickLabel properties for a log axis contain cell arrays with the full TeX markup used for the tick labels. In R2014a and earlier, these properties contain a character array with only the exponent values for the tick marks.

Starting in R2014bR2014a and Earlier
semilogx(1:10000);
ax = gca;
ticks = ax.XTickLabel
class(ticks)
semilogx(1:10000);
ax = gca;
ticks = get(ax,'XTickLabel')
class(ticks)
ticks = 

    '10^{0}'
    '10^{1}'
    '10^{2}'
    '10^{3}'
    '10^{4}'

ans =

cell
ticks =

0
1
2
3
4

ans =

char

To extract just the exponent values from the tick label property, use the regexprep function.

expression = '\d*\^\{(\-?\d*)\}';
replace = '$1';
exponents = regexprep(ticks,expression,replace)
exponents = 

    '0'
    '1'
    '2'
    '3'
    '4'

See Also