Convert x-axis values to datetime
1 Comment
Accepted Answer
More Answers (2)
1 Comment
There is no documented way to directly change the ruler type, but you can do it by plotting NaT (not a time), for example:
ax = axes; p = plot(NaT,NaN); delete(p);
Note that most plotting commands will reset the axes, so if you want to add things to the axes created in my example you will likely need to turn on hold. In addition, this will only work if the axes is empty. If hold is on, and you try to plot a different datatype, you will get an error about incompatible datatypes.
The specifics depend on what you are trying to do and the specific plotting commands. I believe any plotting commands which "understand" datetime (including plot, scatter, etc.) will error if you try plotting using a different datatype while hold is on. However, I believe other commands which are more low-level (and don't directly understand datetime, such as text and patch) will allow you to plot using numeric data into an axes configured for datetime data. In order for this to work, you need to use ruler2num to convert your data into doubles (in most situations, datenum will not do the conversion correctly).
You said it isn't an option to call plot with datetime inputs, why is that? What are you trying to plot? What is your overall goal?
2 Comments
Categories
Find more on Axes Appearance 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!