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

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))

 Risposta accettata

xticks([0:20:700])

8 Commenti

Thank you so much for your help. However, I am getting an error: "Undefined function 'xticks' for input arguments of type 'double'."
If it helps, here is the line of code that I used to plot my graph: plot(Time, Data0(:,1))
Would you happen to have any additional advice?
It should not give any error. Are you sure that you have xticks function in your MATLAB folder?
Edit: It has nothing to do with your code. You just write it after your plot command:
plot(Time, Data0(:,1));
xticks([0:20:700])
Not having the xticks command in my folder is probably the problem. Could I bother you to give me a run down on how to install that command in my matlab folder?
Put the file in this zip into your current directory.
Sorry to bother you again, but I added the folder to my directory and am now getting a new error:
Undefined variable "matlab" or class "matlab.graphics.internal.ruler.rulerFunctions".
Error in xticks (line 33) varargout = matlab.graphics.internal.ruler.rulerFunctions(mfilename, nargout, varargin);
would you happen to have any additional suggestions? Thanks again for all of your help
Birdman
Birdman il 22 Nov 2017
Modificato: Birdman il 22 Nov 2017
Copy the m file and paste it to the following place:
C:\Program Files\MATLAB\R2017a\ toolbox\matlab\graph3d
I use R2017a, your version is whatever you are using and also it may be located somewhere, find it. The important part is bolded part.
I was able to get it to work. Thanks a lot for your help and assistance. Much appreciated friend.
@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.

Accedi per commentare.

Più risposte (1)

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 Commenti

I appreciate the help. This method worked as well. Thanks for your help friend!
+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.

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by