How to plot Date time series in MATLAB?

Illustration
isabellewilliams - 2021-01-04T12:57:57+00:00
Question: How to plot Date time series in MATLAB?

I am facing difficulties in  plotting my time series data. I write code like this but doesnt work.   data3=readtable ('PRICE_AND_DEMAND_Jan.csv') Date_Time = data3(:,2); datecell=table2cell(Date_Time); load = data3(:,3); A = table2array(load) p=datenum(datecell); plot(datenum(datecell), A) datetick('x', 'dd-mmm-yyyy HH:MM:SS') % datetick('x', 'dd-mmm-yyyy HH:MM:SS')

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

try  it:

 

data3=readtable ('PRICE_AND_DEMAND_Jan.csv')
Date_Time = data3(:,2);
datecell=table2cell(Date_Time);
load = data3(:,3);
A = table2array(load)
formatIn='dd-mm-yy HH:MM'
p=datenum(datecell,formatIn);
plot(p, A)
datetick('x', 'dd-mmm-yyyy HH:MM')
set(gca,'XTickLabel',datestr(p),'XMinorGrid','on')
grid


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!