R2015a plot problem with ticklabel definition

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(1),'ytick',-200:50:200)
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 日

0 投票

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 月 21 日
set(hAx(2),'YTickLabel',num2str(y2(:), '%0.2f'))
Still no luck!! The negative values aren't getting printed.
Walter Roberson
Walter Roberson 2020 年 2 月 22 日
No more tick labels will be output than you have defined for tick positions. You define the tick positions with linspace of length 5.
Your vector is long, 2001 elements. You do not want to create a tick label for each one of those.
Angshuman Podder
Angshuman Podder 2020 年 2 月 22 日
Is there a way of doing what I desire: Showing the output within bounds and in a certain format along the right axis.
Walter Roberson
Walter Roberson 2020 年 2 月 22 日
hAx(2).YRuler.TickLabelFormat = '%0.1f';
without setting the YTick or YTickLabel properties (unless the automatically generated values turn out not to be good enough.)
This requires R2014b or later.
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 日

0 投票

Well, you have set you ytick labels to:
num2str(y2(:), '%0.1f')
Maybe you meant?
num2str(linspace(-0.8,0.8,5), '%0.1f')
Blessings,
Spencer

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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeAxes Appearance についてさらに検索

タグ

質問済み:

2020 年 2 月 21 日

コメント済み:

2020 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by