Problem in setting Yaxis value
조회 수: 3 (최근 30일)
이전 댓글 표시
I am using MATLAB 2015a. After going through the Q&A I finally wrote the command lines to set the Yaxis values as exponent, but its not working.
Here is the code
x = linspace(0,5,1000);
y = 100*exp(x).*sin(20*x);
plot(x,y)
ax = gca;
ax.YAxis.Exponent = 2;
Its showing this error "
No appropriate method, property, or field 'YAxis' for class
'matlab.graphics.axis.Axes'.
Error in rough6 (line 32)
ax.YAxis.Exponent = 2;"
Please help me to convert the Yaxis value in desired exponent form.
Thanks
댓글 수: 0
채택된 답변
Star Strider
2018년 8월 25일
I don’t remember when that was introduced. It was obviously after R2015a.
One approach to a work-around:
x = linspace(0,5,1000);
y = 100*exp(x).*sin(20*x);
plot(x,y)
ax = gca;
% ax.YAxis.Exponent = 2;
yt = ax.YTick;
xpnt = 2;
new_tick_lbls = 10.^log10((10^-xpnt)*abs(yt)).*sign(yt);
ytlblc = sprintfc('%.0f',new_tick_lbls); % Undocumented: ‘sprintfc’; % Undocumented: ‘sprintfc’
ax.YTickLabel = ytlblc;
text(min(xlim), max(ylim)*1.05, sprintf('\\times10^{%.0f}', xpnt))
Experiment to get the result you want.
댓글 수: 0
추가 답변 (1개)
Yair Altman
2018년 8월 27일
편집: Yair Altman
2018년 8월 27일
Try this - note that it relies on the hidden/undocumented axis property YRuler (and similarly for XRuler, ZRuler):
ax.YRuler.Exponent = 2;
This works from R2014b onward. Starting in R2015b you can use YAxis instead of YRuler, but YRuler can still be used to this day as a synonym. If you want to take a careful approach in case YRuler will someday stop working, do this:
try
ax.YAxis.Exponent = 2;
catch
ax.YRuler.Exponent = 2;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!