I realize that my implementation requires more work than the example on the Mathworks Help website, but their results resulted in date ticks that did not lie on all of the correct dates for my example. Years = ĭates(k) = datenum(years(k), months(k), days(k)) Next, set the ticks to correspond to your date numbers, use datestr to convert your date numbers to date strings and set the tick labels to the date strings. After that, convert those vectors to date numbers, and plot the date numbers against your data.
If you select the output, it auto highlights the commands caused it to. The MATLAB editor contains the live script where you can run multiple commands together and can see the result immediately. You would start by creating vectors for the days, months and years that you want to plot. That is, the second half of the plot (after the Nyquist frequency) is just a mirror image of the first half. Do as much in the script as you can easily do to save time tweaking plots manually. Figures may be edited graphically after they are created. y1 on primary (left) axis, y2 on secondary (right) axis. Matlab uses the output of datenum for x-axis data on a plot.įor example, assume that you want to plot data over 3 years at 6-month intervals. plotyy(x1,y1,x2,y2) - plot with a secondary y-axis. To retrieve the date and time from datenum, the user can use datevec. To create a plot with a linear scale on the x-axis. Using datenum, the user can specify a date and time with either a string or several arguments. MATLAB knows of other types of plots as well: To plot the solution curve use ezplot: ezplot(sol, 0. Matlab encodes every date into a number, starting with Januas the number 1. Don’t worry, using Matlab for this task is not that hard and, like most of Matlab’s functions, allows a considerable degree of versatility.Ī few functions with which a Matlab user should get familiar are datenum, datevec and datestr. Excel has an easy way to plot data on a date axis, but to use a date axis in Matlab requires familiarity with a few functions.
Many times, an analyst will initially use Excel, but then decide that he or she wants more analytical capabilities or plotting options. plotyy(x1,y1,x2,y2) - plot with a secondary y-axis.
#Matlab 2008 plot with secondary axis how to
One of the most common questions for Matlab users is how to plot data on a date axis. axis auto, axis tight, axis square, axis equal axis manual use with hold on to keep the axis limits from the rst plot.