Amitay Tsinis
Amitay Tsinis

Reputation: 340

How to draw a rectangle between "datetime" data type and a numeric data type in MATLAB

assume I have X,Y

x=[03/01/2017,24/01/2017]% datetime type
y=[1000,2000] % numeric value

How can I draw a rectangle between those "coordinates" I am having trouble since one of them its DateTime value and the other one is numeric. using a plot function? thanks.

Upvotes: 0

Views: 387

Answers (2)

Lasse
Lasse

Reputation: 36

try:

x = datetime([2017,2017],[1,1],[3,24]); % x = [03/01/2017,24/01/2017]
y = [1000,2000];
fill(x([1,2,2,1]),y([1,1,2,2]),'red')

It doesn't matter that x is datetime and y is numeric

Upvotes: 0

Rijo Kuriakose
Rijo Kuriakose

Reputation: 184

The date time can't be treated as coordinates. If you are so sure to plot the rectangle you may need to convert the date time into a serial date number...

    x = datenum(x);

Upvotes: 0

Related Questions