MATLAB: How to plot a datetime vs data within a cell array

datetime plotting

Hello! Say I have a nx2 cell array named CELL with the following data types per column:
column 1: datetime
column 2: double
Whenever I try to plot using plot(CELL{:,1},CELL{:,2}), the following error occur:
"Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data inputs which can be converted to double. "
NOTE: I also tried cell2mat(CELL{:,1}) to try if I can convert the datetime column into an array but the following error occurs:
"CELL2MAT does not support cell arrays containing cell arrays or objects."
May I ask how I can plot the datetime cell column against the double cell column? Thank you very much in advance.

Best Answer

You almost certyainly do not want to store your data like that. For one thing, cell arrays are designed for complete generality, anything can be in any element, so you will find things that involve homogeneous data to be clumsy or unworkable (as you found). For another, the memory footprint will be much larger.
Use a table, or in this case a timetable. Not sure how you got where you are, but it's easy to convert. Say you have this cell array:
>> C
C =
10×2 cell array
{[01-Jul-2019]} {[0.81472]}
{[02-Jul-2019]} {[0.90579]}
{[03-Jul-2019]} {[0.12699]}
{[04-Jul-2019]} {[0.91338]}
{[05-Jul-2019]} {[0.63236]}
{[06-Jul-2019]} {[0.09754]}
{[07-Jul-2019]} {[ 0.2785]}
{[08-Jul-2019]} {[0.54688]}
{[09-Jul-2019]} {[0.95751]}
{[10-Jul-2019]} {[0.96489]}
>> TT = table2timetable(cell2table(C,'VariableNames',{'Time','X'}))
TT =
10×1 timetable
Time X
___________ _______
01-Jul-2019 0.81472
02-Jul-2019 0.90579
03-Jul-2019 0.12699
04-Jul-2019 0.91338
05-Jul-2019 0.63236
06-Jul-2019 0.09754
07-Jul-2019 0.2785
08-Jul-2019 0.54688
09-Jul-2019 0.95751
10-Jul-2019 0.96489
At that point, plotting is simple.
>> plot(TT.Time,TT.X)
But better still, create the timetable to begin with, instead of the cell array.