How to put date ticks on x axis in Matlab? -


I have a text file containing two columns, the date in the first column (yyyy-mm in this format) and the second column An integer text file is a matrix of 2 * 144 in this way:

  1996-06 23 1996-07 53 1996-08 12 1996-09 21 ...   

I read the second column of the file by ImportsData and I do some operations on the second column but in the end they still remain 144. I can plot random numbers on the X axis, but I can not plot dates as X axis I need a vector of the same size, but I want to stay for only 12 years from 1996 to 2007. Yes, not all months on X-axis I am new to MATLAB and I would appreciate any advice.

Here is the full version of my code and error and I know that I need a matrix of 1 * 144 Date:

The best part is that to import your date vector properly on the first date. You get a time vector length compared to your data.

To do this, you give more control to textscan ( importdata ). Import your data by importing your data, by looking at the code you provided in your previous question: import your data (textscan gives you more control) fid = fopen ('2.txt', 'r'); % // Open your file data = textscan (fid, '% s% f'); Import% // content fclose (fid); Close the% // file %% // the time of your variable = dateanm (data {:, 1}, 'yyyy-mm'); Convert the% // text string into the matbab serial date format C = data {:, 2}; Separate

, after that you have the same variable in C that you get with importdata , But you also have your original time vector (same length) in variable time

, then run your calculation code ( repeated here) No, just the same code written by you ). Then on display, use:

  %% // result f = display the shape; Plot (time, c, '.'); Hold on plot (time, L_Tilde, 'g-.'); Plot (time, UTilde, 'g.'); DateFormat = 10; Tips: Use the  datetick  command after  plots  ( plot  ) ('x', dateFormat)   

Code> command can otherwise reset its tick) In writing, it will only show years, but since you have imported your original date / time value, you can set a separate dateFormat , which will display the month and year.


Edit: To complete the answer based on the comment. By default, Matlab automatically ticks the marks, grid lines and labels, trying to not overload the data by adding ticks at each point of the point. If you want to override this behavior and want to control the exact vacancies or position of the ticks, then you have to tell Matlab where to place them.

To do this, we will define a vector of dates to make your likes, then ask Matlab to draw tiles in these places.

  tickStep = 2; % // The year you want, Tikedad = Detainam (1996: Tic Fitch: 2008, 1,1); % // A Vector of Tick Status Set (GCA, 'Exact', Tickets, 'Exactilebase', Datastar (Tickets, 'Yay'))% // sets the status of each Tick and the label   

You can change the year step to 1 or anything that looks good for your data if you go this way, forget the last 2 rows of code in the above solution Go. There is no need to use the datetick in any way because we set the tick string ( XTickLabel ) on the same line where we have their position ( XTick ).

If you want to modify the output format, take a look at the different ones.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -