How can I add additional tics to the x-axis scale in my graph?
1 view (last 30 days)
Show older comments
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))
0 Comments
Accepted Answer
Birdman
on 22 Nov 2017
xticks([0:20:700])
8 Comments
Jan
on 23 Nov 2017
Edited: Jan
on 23 Nov 2017
@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.
More Answers (1)
KL
on 22 Nov 2017
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 Comments
Jan
on 23 Nov 2017
+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.
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!