Plot Excel Time Series in Matlab
2 views (last 30 days)
Show older comments
Hi,
I have a seemingly easy Problem. Attached is a workspace (see ws_test.mat) with two vectors (VarNames1=Dates and VarNames2=Prices). Dates are just businessdays (no Saturdays and Sundays). Creating a chart in Excel from these data was quite easy.
Now I wonder how it is possible to create a chart with monthly dates on the x-axis in Matlab. And further, whether there is an easy possibility to convert daily data in monthly data, where the relevant date is the last day of a month.
Many thanks in advance!
Kind Regards, Alex
3 Comments
Accepted Answer
Star Strider
on 13 Jul 2014
- No .mat file attached.
- Monthly dates are easy with the datetick function.
- How do you want ‘to convert daily data in monthly data’? Minimum, maximum, median, mean, mean ± standard error, high-low-close, ... ?
More Answers (1)
dpb
on 13 Jul 2014
Edited: dpb
on 13 Jul 2014
It's only slightly more of a problem in Matlab. What you need, specifically, is slightly dependent upon the format of the date column but the deal is to convert those dates to Matlab datenum 's and plot against those. Then use datetick to display the axis in time units. This is what Excel does just a little more is hidden behind the magic curtain...
doc datenum
doc datetick
for details. There's a current thread I've demonstrated on the usenet newsgroup besides the examples in the documentation that might be of interest/help at...
As for the end-of-month, that also is pretty simple and approachable in one of several ways, the simplest probably being to compute the year,month,day vectors from the data and locate the positions where the month changes ( diff is good for such jobs) as unless it's in a financial toolbox or somesuch Matlab doesn't have a builtin function to return the last workday in a month.
help timefun
will give you the various time-manipulation functions in base Matlab; what else is in whatever Toolboxes you have installed will be in their documentation. I don't have any of the financial/business related stuff so I'm not familiar with what those might be, if any...
ADDENDUM
Seeing as how you included the Financial Toolbox in the product, I checked and indeed as one would expect there is the function lbusdate
With that simply select the values that match those returned by it over the time of interest.
There's also the financial time series object that you can create that has its own methods and plotting functions you should probably investigate; one would presume they've been designed to make such manipulations simpler than with base Matlab graphics given the nature of financial data--not much sense in the Toolbox if not.
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!