How to force Matlab to only plot some selected strings on the x-axis?

1 回表示 (過去 30 日間)
Write
Write 2015 年 1 月 6 日
回答済み: Star Strider 2015 年 1 月 6 日
I have data linked to specific dates. Let's say e.g.
dates=731948:735938; n=length(dates);
which I can convert to a string of "real dates" by
dates=datestr(dates,0));
starting from 01/02/04 up to 12/5/14. Now I want to use this string as the x-axis of a plot.
plot(rand(n,1));
set(gca, 'XTick', 1:n, 'XTickLabel', dates);
The problem I have now is that there are way to many dates on the x-axis. On the resulting plot you hardly can see anything. So my question is how can I select only lets say every 100th date to be plotted on the x-axis?
Thanks already for your help.

回答 (2 件)

Julian Hapke
Julian Hapke 2015 年 1 月 6 日
set(gca, 'XTick', 1:100:n, 'XTickLabel', dates(1:100:n,:));

Star Strider
Star Strider 2015 年 1 月 6 日
Consider the datetick function.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by