MATLAB: How to connect two plotted points in a timeseries with a vertical line

2d plottime series

I wrote a script that extracts data from a weather station so that I have a timeseries for the average temperature, high temp, and low temp for each day in a year. On the timeseries plot I would like to connect the high and low temp for each day with a vertical line. Is there a way to do this?

Best Answer

See if the errorbar function will do what you want.
Note that for the errorbar function, the line lengths are in this instance ‘mean-low’ for the low-temperatures, and ‘high-mean’ for the high-temperatures. Those will be the upper and lower lengths you will give to the function.
H = [20 22 25 19 21]'; % Highs
L = [11 15 21 12 17]'; % Lows
M = mean([H L],2); % Means
tmp = [L M H]; % Temperature Data
b = timeseries(tmp,[1 2 3 4 5]); % ‘timeseries’ Object
figure(1)
errorbar(b.Time, b.Data(:,2), b.Data(:,2)-b.Data(:,1), b.Data(:,3)-b.Data(:,2))
grid
set(gca, 'XLim',[0 6])
This will probably work for you (with some modifications to work with your data).