Why doesn't Timetable command accept my time,data input?

Hi All
I use the command
TT = timetable(t,X);
but I get the following error, despite having defined t as a nx1 matrix and X the same
Error using timetable (line 291)
Provide datetime or duration vector for row times to create timetable.
How should I debug it ?

 Accepted Answer

The error message tells you what's wrong.
"Provide datetime or duration vector for row times to create timetable."
Apparently t is not a datetime or duration or perhaps it's not a vector. To determine which is the problem you could just look at the content of the variable. You could also run these two diagnostic lines.
class(t)
size(t)
If you've got a datetime or duration variable that is not a vector, you could convert it to a vector using
t(:)
If t is not a datetime or duration, you'll need to convert it to one of those classes. I'd be glad to help out if you get stuck.

7 Comments

Thank you for your answer and offering to help. I appreciate that.
well I tried to convert my " double " variable t of size n x 1 ( n can be whatever) to datetime. using this link
t1 = datetime(t,'InputFormat','yyyyMMddhhmmss','Format','dd/MM/yyyy hh:mm:ss');
and I get :
Error using datetime (line 569)
Numeric input data must be a matrix with three or six columns, or else three, six, or seven
separate numeric arrays. You can also create datetimes from a single numeric array using the
'ConvertFrom' parameter.
First you have to convert your encoded dates to something Matlab can understand. This solution converts your datetime integers to character arrays and then to date vectors. The date vectors are used as input to datetime.
t = 19990101010000:50000:(19990101010000+1000000); % demo data
dv = datevec(compose('%d',t),'yyyyMMddhhmmss');
t1 = datetime(dv,'Format','dd/MM/yyyy hh:mm:ss');
You may be able to skip the conversion from date string to date vec,
datetime(compose('%d',t),'InputFormat','yyyyMMddhhmmss')
Thank you very much. but it's completely incomprehensible for me , why do I need such a strange and complicated formatting for time , while rainflow histogram calculation, only needs the vertical axis values and time can be any thing ? also , I have one value for time for each row as a number like : 0 ; 0.002 ; 0.0035 >> these are the first three rows. I also don't know how should MY dv look like for my time variable, given that I necessarily don't have the time for each t I get !
" it's completely incomprehensible for me ,"
Which part?
"why do I need such a strange and complicated formatting for time ,"
What is strange about the formatting? This is very standard. The first 5 values of t1 are shown below.
t1(1:5)
ans =
5×1 datetime array
01/12/1998 01:01:00
01/12/1998 06:01:00
01/12/1998 11:01:00
01/12/1998 04:01:00
01/12/1998 09:01:00
The format of datetime values can be changed to almost any format you desire. Could you explain what kind of datetime values you expect to see?
dear Adam
What I desire to do , is to use this time vector or whatever format, in the rainflow 3d plot , as you see bellow, the top time history plot, you have Amplitude vs Time, while if I use
rainflow(X,'est') , I will only have Amplitue vs Samples.
to be able to have the time, I need to format the time double variable into the date and time, but the thing is : why should I ? maybe I receive a data acquisition results that the date - time is not mentioned in it. should I insert something arbitrary ?
the code :
fs = 100;
t = seconds(0:1/fs:100-1/fs)';
x = randn(size(t));
TT = timetable(t,x);
Display the reversals and the rainflow matrix of the signal.
rainflow(TT)
and link to the code : in the middle of the page : Cycle counting for timetable:
If the x axis should represent time, the use of datetime values would be ideal. If the x axis should represent durations, it would be easy to convert the datetime values to duration. Either way the datetime values are more useful than other date/time formats.
" I need to format the time double variable into the date and time, but the thing is : why should I ?"
Here's an example why datetime values are the appropriate representation of time variables.
Suppose I have a vector of timestamps in the format yyyyMMddhhmmss. The two values below show Feb 1 2020 to March 1 2020. How many days are between those two days? How many hours? That can't be calculated from these values without an extensive amount of work. The numbers don't actually represent date and time - they are merely a code that you defined by the format above.
t = [20200201000000, 20200301000000]
If those values were converted to datetime values, the numbers become meaningful and interpretable. You can easily compute days, hours, months, etc and the spacing of the datetime ticks along the x-axis will be meaningful.
" maybe I receive a data acquisition results that the date - time is not mentioned in it. should I insert something arbitrary ?"
Missing data is a problem no matter what format the time variables are in. Sometimes the context of the data will help to decide how to fill those values. For example, are the data acquired at a fixed rate? Can the surrounding known times be used to fill in the missing times? Can the missing values be estimated using linear interpolation?

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 23 Dec 2019

Commented:

on 26 Dec 2019

Community Treasure Hunt

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

Start Hunting!