MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

Matlaber
0

How to plot a specific value in Y-axis?

Matlaber
さんによって質問されました 2019 年 2 月 12 日
最新アクティビティ Adam Danz
さんによって 編集されました 2019 年 2 月 25 日 13:17
I want to plot a specific range of Y-axis and not the entire Y-axis.
For example:
load sunspot.dat
year = sunspot(:,1);
avSpots = sunspot(:,2);
plot(year, avSpots)
untitled.jpg
The Y-axis is from 1700 to 2000
Let say I want to plot from 1750 to 1800, and then 1850 to 1900.
I cannot find any example, use
y = linspace(x1,x2)

  1 件のコメント

Matlaber
2019 年 2 月 12 日
It seemed not working
axis([0 200 1700 1750]);
axis([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes on the current plot.

サインイン to comment.

タグ

1 件の回答

回答者: Adam Danz
2019 年 2 月 12 日
編集済み: Adam Danz
2019 年 2 月 25 日 13:17
 採用された回答

First, your example references the x-axis; not the y-axis. Here's how to plot a portion of the data along the x axis. The same process can be applied to the y-axis.
load sunspot.dat
year = sunspot(:,1);
avSpots = sunspot(:,2);
% select the data you want to include
%'includeIndex' is a logical index that selects which data to include
% This statement selects any data between 1750-1800 and 1850-1900
includeIndex = ((year >= 1750) & (year <= 1800)) | ((year >= 1850) & (year <= 1900));
%plot results, select only included data
plot(year(includeIndex), avSpots(includeIndex))
To plot the two spans of time separately,
idx1 = (year >= 1750) & (year <= 1800);
idx2 = (year >= 1850) & (year <= 1900);
%plot results, select only included data
plot(year(idx1), avSpots(idx1),'r-')
hold on
plot(year(idx2), avSpots(idx2),'b-')

  2 件のコメント

Matlaber
2019 年 2 月 12 日
Thanks.
It seemed figure below:
1.jpg
If let say I want to plot in different figure of:
  1. start to 1750
  2. 1750 to 1800
  3. 1800 to end
Adam Danz
2019 年 2 月 12 日
Yeah, that's very very easy to do. Check out the how I formed the "idx1" or "idx2" variables - you'll do the same except with the years you listed above. To get the starting year, min(year). To get the end year, max(year).

サインイン to comment.



Translated by