Expected timetable data to be numeric.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I am trying to do a sftf(x) function, I have compiled the data and datetime has been combined using:
data = 'TA';
for date = datetime(date, 'InputFormat', 'dd-MM-yyyy hh:mm:ss')
end
I keep getting the error Error using signal.internal.utilities.validateattributesTimetable>localCheckAttribute
Expected timetable data to be numeric.
I am unsure where I'm going wrong. Is the imput of date/time incorrect?
Would using a DateVector be useful? I have 57001 rows in each variable (several variables per brain area, and 12 brain areas), it will be impossible to type it all out as e.g. [2014 10 24 12 45 07]. I have no idea how to do it for all rows.
2 件のコメント
It is unclear what this code is supposed to do:
data = 'TA';
for date = datetime(date, 'InputFormat', 'dd-MM-yyyy hh:mm:ss')
end
Why write a loop with nothing in it? Why define DATA but not use it? How does this relate to your screenshot?
"I am unsure where I'm going wrong. Is the imput of date/time incorrect?"
We don't know either, because we have no idea what DATE is. Nore what TT is in your screenshot.
Your screenshots show that you apparently call some functions, but we have no idea what is in those functions.
If you want help debugging this please upload your code files by clicking the paperclip button.
Antoinette Burger
2023 年 2 月 16 日
編集済み: Antoinette Burger
2023 年 2 月 16 日
Hi @Stephen23, apologies for not being clearer with my question. @Star Strider this might be useful info on how the date/time are imported.
My steps are:
- Use edfread to read .edf file, which results in the 57000x1 output in 'initial_ouput.png'.
- I use the variable names, to run change_to_average.m, which averages each 64x1 cell to one value per RecordTime point (as in initial_output).
- I use the output from change_to_average.m to create a .csv file (CSV_file_precgyrus.png), where I add the date and start time ('time') (obtained from edfinfo function) of the time period. The RecordTime value is incorporated into the 'time' column when it is dragged to the end.
- I import the .csv file into MATLAB with readtable function as 'TA'. I then use 'date_and_time_combined.m' to combine the date and time to create 'datetime'. data = 'TA' is just making sure the correct file is used.
- I then create a timetable (necessary for sftf function), 'TT', for the sftf function.
- I fun sftf, but get the error 'Error using signal.internal.utilities.validateattributesTimetable>localCheckAttribute. Expected timetable data to be numeric.'
I hope this is a bit clearer? I don't know whether the / in the date or the : in the time is an issue as it's not numeric?
採用された回答
Star Strider
2023 年 2 月 16 日
編集済み: Star Strider
2023 年 2 月 16 日
It would help to have the data.
I am not certain how the ‘date’ and ‘time’ values are being imported.
One possibility:
DateTime = datetime(TT.date, 'InputFormat','dd/MM/yyyy') + timeofday(datetime(TT.time, 'InputFormat','HH.mm.ss'))
It would also be helpful to know what the ‘time’ values represent. Something like this may be necessary —
time = {'14.11.0020'; '14.11.0021'}
time = 2×1 cell array
{'14.11.0020'}
{'14.11.0021'}
HHmmssSS = cellfun(@(x){x(end-9:end-8) x(end-6:end-5) x(end-3:end-2) x(end-1:end)},time, 'Unif',0);
timec = cellfun(@(x)sprintf('%02d:%02d:%02d.%02d',str2double(x)),HHmmssSS, 'Unif',0);
T = datetime(timec, 'InputFormat','HH:mm:ss.SS', 'Format','HH:mm:ss.SS')
T = 2×1 datetime array
14:11:00.20
14:11:00.21
For whatever reason, 'InputFormat','HH.mm.ssSS' fails here.
EDIT — (16 Feb 2023 at 18:27)
Corrected typographical errors. Code unchanged.
.
17 件のコメント
Antoinette Burger
2023 年 2 月 16 日
@Star Strider I'd love to send you the data, but is 100mb big.
Antoinette Burger
2023 年 2 月 16 日
@Star Strider I tried what you suggested, it gives an error at
HmmssSS = cellfun(@(x){x(end-9:end-8) x(end-6:end-5) x(end-3:end-2) x(end-1:end)},time, 'Unif',0);
Unrecognized function or variable 'time'.
Star Strider
2023 年 2 月 16 日
I need to create a version of your timetable to demonstrate the correct coding.
It would actually be —
date = datetime({'18/01/2021'; '18/01/2021'}, 'Format','dd/MM/yyyy');
time = {'14.11.0020'; '14.11.0021'};
LACIN1 = rand(2,1);
T = table(date,time,LACIN1);
TT = table2timetable(T)
TT = 2×2 timetable
date time LACIN1
__________ ______________ _______
18/01/2021 {'14.11.0020'} 0.95765
18/01/2021 {'14.11.0021'} 0.70926
T = timetable2table(TT); % Temp[orarily Conmvert To 'table'
HHmmssSS = cellfun(@(x){x(end-9:end-8) x(end-6:end-5) x(end-3:end-2) x(end-1:end)},TT.time, 'Unif',0);
timec = cellfun(@(x)sprintf('%02d:%02d:%02d.%02d',str2double(x)),HHmmssSS, 'Unif',0);
DateTime = T.date + timeofday(datetime(timec, 'InputFormat','HH:mm:ss.SS', 'Format','HH:mm:ss.SS'));
DateTime.Format = 'dd/MM/yyyy HH:mm:ss.SS'
DateTime = 2×1 datetime array
18/01/2021 14:11:00.20
18/01/2021 14:11:00.21
T = addvars(T,DateTime,'Before','date') % Add: 'DateTime'
T = 2×4 table
DateTime date time LACIN1
______________________ __________ ______________ _______
18/01/2021 14:11:00.20 18/01/2021 {'14.11.0020'} 0.95765
18/01/2021 14:11:00.21 18/01/2021 {'14.11.0021'} 0.70926
TT = table2timetable(T) % Convert Back To 'timetable'
TT = 2×3 timetable
DateTime date time LACIN1
______________________ __________ ______________ _______
18/01/2021 14:11:00.20 18/01/2021 {'14.11.0020'} 0.95765
18/01/2021 14:11:00.21 18/01/2021 {'14.11.0021'} 0.70926
VN = TT.Properties.VariableNames
VN = 1×3 cell array
{'date'} {'time'} {'LACIN1'}
That should work.
.
Antoinette Burger
2023 年 2 月 16 日
Star Strider
2023 年 2 月 16 日
As always, my pleasure!
Antoinette Burger
2023 年 2 月 16 日
編集済み: Antoinette Burger
2023 年 2 月 16 日
@Star Strider, one last issue:
I get the error:
Error using datetime
Unable to convert the text to datetime using the format 'HH:mm:ss.SS'.
on this line:
DateTime = T.date + timeofday(datetime(timec, 'InputFormat','HH:mm:ss.SS', 'Format','HH:mm:ss.SS'));
Any ideas?
Walter Roberson
2023 年 2 月 16 日
Could you show a few of the entries from timec ? The first 3 perhaps? And verify that
datetime(timec(1:3), 'InputFormat','HH:mm:ss.SS', 'Format','HH:mm:ss.SS')
does indeed fail ?
Antoinette Burger
2023 年 2 月 16 日
Walter Roberson
2023 年 2 月 16 日
Please show us timec(1:3)
Antoinette Burger
2023 年 2 月 16 日
I now get this:
Error using cellfun
Input #2 expected to be a cell array, was char instead.
Error in date_and_time_combined (line 16)
timec(1:3) = cellfun(@(x)sprintf('%02d:%02d:%02d.%02d',str2double(x)),'HH:mm:ss.SS', 'Unif',0)
Antoinette Burger
2023 年 2 月 16 日
編集済み: Antoinette Burger
2023 年 2 月 16 日
Do these:
HHmmssSS = cellfun(@(x){x(end-9:end-8) x(end-6:end-5) x(end-3:end-2) x(end-1:end)},time, 'Unif',0);
timec = cellfun(@(x)sprintf('%02d:%02d:%02d.%02d',str2double(x)),HHmmssSS, 'Unif',0);
apply only when one variable (LACIN1) is used? Or does it need to be changed to include the entire table/timetable rows?
If it needs to be modified, that might be the issue as I've included all the rows of 'time' in the table/timetable. That prints correctly.
Walter Roberson
2023 年 2 月 16 日
Notice that in his demonstration, Star Strider used a different line of code,
HHmmssSS = cellfun(@(x){x(end-9:end-8) x(end-6:end-5) x(end-3:end-2) x(end-1:end)},TT.time, 'Unif',0);
That code applies to all rows in the table.
Please show us
celldisp(HHmmssSS(1:3))
celldisp(timec(1:3))
Star Strider
2023 年 2 月 16 日
@Antoinette Burger — I assumed ‘time’ is a cell array because I cannot imagine it being anything else and still having that format.
Can you share a few rows of your Excel file? That should be all that is necessary.
One way to do that would be to save it as a slightly different name to crreate a copy of it (the original file will remain unchanged) and then delete all but five or ten rows of the copied and renamed file. Alternatively, just copy the first few rows of the file and save it in a different name. (I am not certain which would be easiest.)
Then, upload the shortened copy here.
Antoinette Burger
2023 年 2 月 16 日
@Star Strider of course! Here is a sample.
Antoinette Burger
2023 年 2 月 16 日
Thank you @Walter Roberson for the clarification. I'm still very novice, so I don't always understand all the syntax.
Here is the output of what you requested.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1298125/sample_left_cing_table.csv';
T = readtable(filename)
T = 26×9 table
date time LACIN1 LACIN2 LCING1 LCING2 LPREM1 LPREM2 LPREM3
__________ __________ ________ _______ _______ ________ _______ _______ _______
18/01/2021 14.11.0020 -14.38 -74.324 2.7041 29.355 14.173 -27.826 -25.795
18/01/2021 14.11.0021 18.468 -38.879 10.11 6.1393 6.3387 -43.129 -38.489
18/01/2021 14.11.0022 18.073 -45.613 7.6181 8.3907 -20.831 -45.916 -37.388
18/01/2021 14.11.0023 -0.11631 -66.843 -17.616 -9.479 -56.138 -65.593 -53.459
18/01/2021 14.11.0024 1.7155 -67.337 -16.931 11.859 -22.044 -38.439 -32.711
18/01/2021 14.11.0025 -5.0136 -59.927 -9.7489 30.252 -46.228 -50.356 -37.671
18/01/2021 14.11.0026 17.782 -42.182 6.3221 31.556 -34.132 -43.719 -29.907
18/01/2021 14.11.0027 -13.998 -62.519 12.54 33.027 -10.131 -19.091 -15.29
18/01/2021 14.11.0028 -33.077 -73.962 1.9814 18.331 8.212 -32.35 -35.789
18/01/2021 14.11.0029 -19.747 -61.032 7.7717 8.2079 -6.9867 -44.886 -39.457
18/01/2021 14.11.0030 -18.16 -63.325 0.36553 16.532 -39.868 -41.455 -30.028
18/01/2021 14.11.0031 -31.286 -72.982 -11.294 -5.2504 -67.395 -69.119 -37.654
18/01/2021 14.11.0032 -19.739 -67.931 -25.272 -0.53584 -90.478 -67.341 -30.169
18/01/2021 14.11.0033 -20.902 -72.683 -5.2504 1.4331 -33.874 -61.63 -44.263
18/01/2021 14.11.0034 -32.379 -82.27 15.311 10.368 -14.223 -45.459 -40.911
18/01/2021 14.11.0035 6.4342 -51.806 32.263 16.021 -23.382 -42.365 -43.054
class(T.time)
ans = 'datetime'
class(T.time(1))
ans = 'datetime'
T.time(1)
ans = datetime
14.11.0020
T.time(1).Format
ans = 'dd.MM.uuuu'
readtable() by default is interpreting the time column as dd.MM.uuuu not as text . You would have to break part the pieces and reconstruct them, or else you would have to use readtable options to tell it that the variable should be text.
options = detectImportOptions(filename);
options = setvartype(options, 'time', 'char');
T = readtable(filename, options)
T = 26×9 table
date time LACIN1 LACIN2 LCING1 LCING2 LPREM1 LPREM2 LPREM3
__________ ____________ ________ _______ _______ ________ _______ _______ _______
18/01/2021 {'14.11.20'} -14.38 -74.324 2.7041 29.355 14.173 -27.826 -25.795
18/01/2021 {'14.11.21'} 18.468 -38.879 10.11 6.1393 6.3387 -43.129 -38.489
18/01/2021 {'14.11.22'} 18.073 -45.613 7.6181 8.3907 -20.831 -45.916 -37.388
18/01/2021 {'14.11.23'} -0.11631 -66.843 -17.616 -9.479 -56.138 -65.593 -53.459
18/01/2021 {'14.11.24'} 1.7155 -67.337 -16.931 11.859 -22.044 -38.439 -32.711
18/01/2021 {'14.11.25'} -5.0136 -59.927 -9.7489 30.252 -46.228 -50.356 -37.671
18/01/2021 {'14.11.26'} 17.782 -42.182 6.3221 31.556 -34.132 -43.719 -29.907
18/01/2021 {'14.11.27'} -13.998 -62.519 12.54 33.027 -10.131 -19.091 -15.29
18/01/2021 {'14.11.28'} -33.077 -73.962 1.9814 18.331 8.212 -32.35 -35.789
18/01/2021 {'14.11.29'} -19.747 -61.032 7.7717 8.2079 -6.9867 -44.886 -39.457
18/01/2021 {'14.11.30'} -18.16 -63.325 0.36553 16.532 -39.868 -41.455 -30.028
18/01/2021 {'14.11.31'} -31.286 -72.982 -11.294 -5.2504 -67.395 -69.119 -37.654
18/01/2021 {'14.11.32'} -19.739 -67.931 -25.272 -0.53584 -90.478 -67.341 -30.169
18/01/2021 {'14.11.33'} -20.902 -72.683 -5.2504 1.4331 -33.874 -61.63 -44.263
18/01/2021 {'14.11.34'} -32.379 -82.27 15.311 10.368 -14.223 -45.459 -40.911
18/01/2021 {'14.11.35'} 6.4342 -51.806 32.263 16.021 -23.382 -42.365 -43.054
class(T.time)
ans = 'cell'
class(T.time(1))
ans = 'cell'
T.time(1)
ans = 1×1 cell array
{'14.11.20'}
dt = datetime(T.time, 'InputFormat', 'HH.mm.ss');
dt = dt - dateshift(dt, 'start', 'day');
T.date = T.date + dt;
T.date.Format = 'yyyy-MM-dd HH:mm.ss'
T = 26×9 table
date time LACIN1 LACIN2 LCING1 LCING2 LPREM1 LPREM2 LPREM3
___________________ ____________ ________ _______ _______ ________ _______ _______ _______
2021-01-18 14:11.20 {'14.11.20'} -14.38 -74.324 2.7041 29.355 14.173 -27.826 -25.795
2021-01-18 14:11.21 {'14.11.21'} 18.468 -38.879 10.11 6.1393 6.3387 -43.129 -38.489
2021-01-18 14:11.22 {'14.11.22'} 18.073 -45.613 7.6181 8.3907 -20.831 -45.916 -37.388
2021-01-18 14:11.23 {'14.11.23'} -0.11631 -66.843 -17.616 -9.479 -56.138 -65.593 -53.459
2021-01-18 14:11.24 {'14.11.24'} 1.7155 -67.337 -16.931 11.859 -22.044 -38.439 -32.711
2021-01-18 14:11.25 {'14.11.25'} -5.0136 -59.927 -9.7489 30.252 -46.228 -50.356 -37.671
2021-01-18 14:11.26 {'14.11.26'} 17.782 -42.182 6.3221 31.556 -34.132 -43.719 -29.907
2021-01-18 14:11.27 {'14.11.27'} -13.998 -62.519 12.54 33.027 -10.131 -19.091 -15.29
2021-01-18 14:11.28 {'14.11.28'} -33.077 -73.962 1.9814 18.331 8.212 -32.35 -35.789
2021-01-18 14:11.29 {'14.11.29'} -19.747 -61.032 7.7717 8.2079 -6.9867 -44.886 -39.457
2021-01-18 14:11.30 {'14.11.30'} -18.16 -63.325 0.36553 16.532 -39.868 -41.455 -30.028
2021-01-18 14:11.31 {'14.11.31'} -31.286 -72.982 -11.294 -5.2504 -67.395 -69.119 -37.654
2021-01-18 14:11.32 {'14.11.32'} -19.739 -67.931 -25.272 -0.53584 -90.478 -67.341 -30.169
2021-01-18 14:11.33 {'14.11.33'} -20.902 -72.683 -5.2504 1.4331 -33.874 -61.63 -44.263
2021-01-18 14:11.34 {'14.11.34'} -32.379 -82.27 15.311 10.368 -14.223 -45.459 -40.911
2021-01-18 14:11.35 {'14.11.35'} 6.4342 -51.806 32.263 16.021 -23.382 -42.365 -43.054
Antoinette Burger
2023 年 2 月 16 日
Thank you thank you thank you thank you!!!!!!!! It's working!!!!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Type Identification についてさらに検索
参考
2023 年 2 月 16 日
2023 年 2 月 16 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!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)
