Expected timetable data to be numeric.

5 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 16 Feb 2023
Edited: Stephen23 on 16 Feb 2023
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
Antoinette Burger on 16 Feb 2023
Edited: Antoinette Burger on 16 Feb 2023
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:
  1. Use edfread to read .edf file, which results in the 57000x1 output in 'initial_ouput.png'.
  2. 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).
  3. 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.
  4. 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.
  5. I then create a timetable (necessary for sftf function), 'TT', for the sftf function.
  6. 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?

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 16 Feb 2023
Edited: Star Strider on 16 Feb 2023
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 Comments
Walter Roberson
Walter Roberson on 16 Feb 2023
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
Antoinette Burger on 16 Feb 2023
Thank you thank you thank you thank you!!!!!!!! It's working!!!!

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!