Plot time series in date format from Excel sheet
Show older comments
The Excel sheet attached contains a date column, which is in the format dd/mm/yyyy.
I would like to create a time-series plot for the prices contained in table A, with the date displayed on the x-axis.
I've tried to convert the dates in the 'date' column to datetime type, then use the plot() function to create the plot, but apparentlty it is of the wrong data type.
My code:
opts = detectImportOptions('fruitvegprices.csv');%detects import options for the file
opts = setvartype(opts,["variety"],"categorical");%changes variety to categorical
data = readtable('fruitvegprices.csv',opts);%import spreadsheet
%apples
apples = data(data.item=="apples",:); %table of just apples
uniq_apples=unique(apples.variety,'stable');%distinct varieties of apple
item=uniq_apples(8);
A=apples(ismember(apples.variety,item),:)
ts=timeseries(A.price);
date = datetime(A.date,'InputFormat','dd-mmmm-yyyy')
plot(date,ts)
How could I resolve this?
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets 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!