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 ?
채택된 답변
Adam Danz
2019년 12월 23일
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
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?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
태그
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
