R2015a plot problem with ticklabel definition

조회 수: 3 (최근 30일)
Angshuman Podder
Angshuman Podder 2020년 2월 21일
댓글: Walter Roberson 2020년 2월 24일
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure % new figure
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
title('Multiple Decay Rates')
xlabel('Time (\musec)')
ylabel(hAx(1),'Slow Decay') % left y-axis
set(hAx(2),'ytick',linspace(-0.8,0.8,5),'YTickLabel',num2str(y2(:), '%0.1f'))
When I run this, I get only positive values for the y axis on the right and the values aren't correct. Any solution??

답변 (2개)

Walter Roberson
Walter Roberson 2020년 2월 21일
편집: Walter Roberson 2020년 2월 21일
You only ask for 5 ticks in your linspace, with labels derived from y2 not from what you linspace. Your first 5 y2 values are all positive.
  댓글 수: 6
Angshuman Podder
Angshuman Podder 2020년 2월 24일
%No public field TickLabelFormat exists for class matlab.graphics.axis.decorator.NumericRuler.
%Error in plotdemo (line 83)
%hAx(2).YRuler.TickLabelFormat = '%0.1f';
The above error pops up. I'm using R2015a.

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

Spencer Chen
Spencer Chen 2020년 2월 21일
Well, you have set you ytick labels to:
num2str(y2(:), '%0.1f')
Maybe you meant?
num2str(linspace(-0.8,0.8,5), '%0.1f')
  댓글 수: 1
Angshuman Podder
Angshuman Podder 2020년 2월 21일
Hi, I want the y2 values to be printed on the right axis in the %0.xxf format.

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


Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by