Using Datetiim to produce array of time points

2 次查看(过去 30 天)
I'm trying to use the Datetime function to produce an array of data points to use as input to an array of impedance values to process and plot. I have entered 8 points for Year, Month, and Day. MATLAB claims this is what it wants, even while it denies the Datetime function and won't work. How can I get this data entered into numerical Year,Month, Day for plotting and analysis?
The datetime function is described here:
https://www.mathworks.com/help/matlab/ref/datetime.html
Thanks.
Sincerely,
Del Ventruella
{ >> Y=[2000;2007;2009;2011;2012;2013;2014;2015]
Y =
2000
2007
2009
2011
2012
2013
2014
2015
>> M = [2;2;2;4;8;11;12;11]
M =
2
2
2
4
8
11
12
11
>> D = [12,17,14,16,8,11,13,14]
D =
12 17 14 16 8 11 13 14
>> X = datetime(Y,M,D) Error using datetime (line 579) Data inputs must be the same size, or any of them can be a scalar.
>> len(Y)= len(Y)= ↑ Error: Expression or statement is incomplete or incorrect.
>> length(Y)
ans =
8
>> length(M)
ans =
8
>> length(D)
ans =
8
>> x = datetime(Y,M,D) Error using datetime (line 579) Data inputs must be the same size, or any of them can be a scalar. }

采纳的回答

Steven Lord
Steven Lord 2017-5-3
Look at the size of the variables Y, M, and D. One of these things is not like the others. Just because two arrays have the same number of elements or the same length does not mean they have the same size. Transpose your D variable and it will work.

更多回答(2 个)

Del Ventruella
Del Ventruella 2017-5-3
That's what I did. I still have a problem in that I'm trying to use the dateTime array as in input for the X-axis components of curvefit toobox. It won't recognize the dateTime array. Is there some way I can convert dateTime to an array of numbers?

Del Ventruella
Del Ventruella 2017-5-3
Perhaps the number of days that have passed since 2000?

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by