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')
farzad
2019 年 12 月 24 日
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 についてさらに検索
タグ
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
