フィルターのクリア

how to put variable xtick label in MATLAB plot?

16 ビュー (過去 30 日間)
Poulomi Ganguli
Poulomi Ganguli 2017 年 10 月 19 日
編集済み: Cam Salzberger 2017 年 10 月 19 日
Hello,
I have multiple files starting from different start and end year and I would like to show it in the figure output from a loop. How to show the start and end year in custom wise.
for example, Startyear = 1918 & endyear = 1982 at a time step of 5
set(gca,'Xtick',sprintf('%s%s', num2str(Startyear): 5: num2str(Endyear - windowlength)))

採用された回答

Cam Salzberger
Cam Salzberger 2017 年 10 月 19 日
編集済み: Cam Salzberger 2017 年 10 月 19 日
Hello Poulomi,
The 'XTick' property must be numeric, and indicates to the axes where to place the tick marks.
The 'XTickLabel' property indicates what to display for labels. I believe this is the property you wish to modify. If there are tick marks for which you do not wish to display labels, you'll want to give them an empty character array or empty string to display. XTickLabel must have the same length as XTick.
-Cam
  4 件のコメント
Poulomi Ganguli
Poulomi Ganguli 2017 年 10 月 19 日
yea but in my case some times years ranging between 1900 to 2013 and in some cases mere 1960 to 2012. For each iteration I am using a forloop and there is no date and month only years. As you mentioned one way could be to use datetime array, how to use it for the above case, I mean variable way in a forloop.
Cam Salzberger
Cam Salzberger 2017 年 10 月 19 日
編集済み: Cam Salzberger 2017 年 10 月 19 日
If you don't have month/day data, you can just say January 1 as a default. It might be misleading, but no more so than when you create a datetime with no hour/minute/second data.
y = 1960:2012;
d = datetime(y, ones(size(y)), ones(size(y)), ...
'Format', 'yyyy');
vals = rand(size(d));
plot(d, vals)
set(gca,'XTick',d(1:5:end))

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by