How can I add additional tics to the x-axis scale in my graph?

2 ビュー (過去 30 日間)
Brittny Freeman
Brittny Freeman 2017 年 11 月 22 日
コメント済み: Jan 2017 年 11 月 23 日
Hello all, I am plotting a graph, and currently the X-axis has a range from 0 seconds to 700 seconds, with tic marks at every 100 second intervals. However, i would like the tics to occur at every 20 seconds. Additionally, is there a graphing tool that will insert vertical lines on the x-axis, so that I could clearly distinguish and highlight the data on the graph between the time inter-valve of say 300s-320s. Any help or suggestions would be very much appreciated. Thanks in advance.
Also, here is the line of code that I used to plot my graph:
plot(Time, Data0(:,1))

採用された回答

Birdman
Birdman 2017 年 11 月 22 日
xticks([0:20:700])
  8 件のコメント
Brittny Freeman
Brittny Freeman 2017 年 11 月 22 日
I was able to get it to work. Thanks a lot for your help and assistance. Much appreciated friend.
Jan
Jan 2017 年 11 月 23 日
編集済み: Jan 2017 年 11 月 23 日
@cvklpstunc: Please do not post code in the forum, which belongs to Matlab's toolbox functions. As you can see in the code:
% Copyright 2015-2016 The MathWorks, Inc.
This means, that it cannot be copied freely. I have removed it in consequence. See https://www.mathworks.com/matlabcentral/answers/322209-is-it-legal-to-publish-the-source-code-of-matlab-s-toolbox-functions.
Nevertheless, adding xticks.m to the current directory is a bad advice. Adding it inside Matlab's toolbox folders is even worse! Don't do this. Leave Matlab's toolbox functions untouched. xticks belongs to Matlab's toolbox and the implementation depends on the Matlab version. Distributing the contents and suggesting to insert it in an unknown Matlab version is near to be destructive. It can cause serious unexpected side effects.
See http://www.mathworks.com/matlabcentral/answers/35676-why-not-use-square-brackets for why to avoid unnecessary square brackets. [] is the operator for concatenation, but 0:20:700 is a vector already.
@Brittny: The function xticks was introduced in R2016b. Do not copy it to another Matlab version. This might cause unexpected error and is not covered by the license conditions. Use KL's suggestion instead.

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

その他の回答 (1 件)

KL
KL 2017 年 11 月 22 日
If you're using older version of matlab,
set(gca,'xtick',0:20:700);
and to draw vertical lines,
line([x1 x2],[y1 y2])
  2 件のコメント
Brittny Freeman
Brittny Freeman 2017 年 11 月 22 日
I appreciate the help. This method worked as well. Thanks for your help friend!
Jan
Jan 2017 年 11 月 23 日
+1. This method is reliable, backward compatible and legal.
Do not copy M-files from the toolbox of another Matlab version. Never and under no circumstances. Even if it seems to work.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by