Plot time series in date format from Excel sheet
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
