MATLAB: Stretching a rectangle over a date axis

MATLAB

Hello, I have a graph with dates as X axis (datetime variables) I'm trying to stretch a rectangle over certain dates (I have the dates stored in a vector), but the problem is that the X axis is datetime and the Y axis is doubles, so MATLAB throws an error. How can I fix this?
for I = 1:1:length(main_idleDateMat(:,1))
startX = main_idleDateMat(I,1);
endX = main_idleDateMat(I,2);
rectangle('Position', [startX idleVecStartHeights(I)-80 (endX - startX) 160]);
end

Best Answer

Ayup, "no can do" it seems...another place TMW either hasn't yet got a round tuit or didn't think it needed to add an overloaded plotting function to take care of the new class object.
All is not lost, however, but it's a regression, indeed. :(
You'll have to revert to the venerable datenum form to plot to subsequently use rectangle or draw the lines directly with plot or line. If you do the former, then will have to also use datetick to format the x-axis as date. All in all, the direct-drawing option may turn out "more better".
ADDENDUM
Use patch. You'll have to provide X,Y vectors to outline the four corners, but it an aliased version has been created that is datetime-aware so TMW has, to their credit, done the most fundamental routine.
Mayhaps they'll eventually get to the rest...
Related Question