Error in histogram plot including datetime

2 views (last 30 days)
Sonima
Sonima on 20 Jan 2019
Answered: Star Strider on 20 Jan 2019
Hi!
I want to plot a histogram in a plot which x-axis is a datetime vector. However i got this error:
Error in histogram (line 145)
[opts,passthrough,dispatch] = parseinput(args,firstaxesinput);
here is my code:
histogram(run(1:12), D1.Date(1:12));
the run vector is double and D1.Date is a datetime vector.
12×1 datetime array
1999-12-31
2000-01-03
2000-01-04
2000-01-05
2000-01-06
2000-01-07
2000-01-10
2000-01-11
2000-01-12
2000-01-13
2000-01-14
2000-01-18
any solution would be much appritiated.

Answers (1)

Star Strider
Star Strider on 20 Jan 2019
You already appear to have the data you want to plot, so histogram may not be the correct choice.
Try this instead:
figure
bar(D1.Date(1:12), run(1:12))
That will plot your data to look like a histogram plot.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!