How do I get exponent values for log axes in MATLAB R2014b?
1 回表示 (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2014 年 8 月 27 日
編集済み: MathWorks Support Team
2021 年 2 月 25 日
I have a plot created using the 'semilogx' function. I am trying to access the exponent values for the tick labels for the 'x' axis. In MATLAB R2014a, I could access the exponent values using the command:
ticks = get(gca,'XtickLabel') which would return a character array of exponent values for the ticks. How do I do the same task in MATLAB R2014b?
採用された回答
MathWorks Support Team
2021 年 2 月 25 日
編集済み: MathWorks Support Team
2021 年 2 月 25 日
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 previous releases these properties contain a character array with only the exponent values for the tick marks.
Starting in R2014b, this code returns the tick labels a cell array with the full TeX markup:
semilogx(1:10000);
ax = gca;
ticks = ax.XTickLabel
ticks =
'10^{0}'
'10^{1}'
'10^{2}'
'10^{3}'
'10^{4}'
class(ticks)
ans =
cell
In R2014a and earlier, this code returns a character array with the exponent values:
semilogx(1:10000);
ax = gca;
ticks = get(ax,'XTickLabel')
ticks =
0
1
2
3
4
class(ticks)
ans =
char
To extract just the exponent values from the tick label property, use the regexprep function with the following syntax.
expression = '\d*\^\{(\-?\d*)\}';
replace = '$1';
exponents = regexprep(ticks,expression,replace)
exponents = '0' '1' '2' '3' '4'
Documentation for the regexprep function is available at the following link:
https://www.mathworks.com/help/matlab/ref/regexprep.html
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!