Azzera filtri
Azzera filtri

I want to import only specific Types of variables using readtable.

6 visualizzazioni (ultimi 30 giorni)
Hello, so I am using 'readtable' to import some text data that I have. I am then using 'table2timetable' to be able to use my data as a time table. The data if have is collected sparatically at different minutes and hours, so I am using
NewData = retime(TimeTableOut,'hourly','mean');
to average the values into a whole hour row.
But I am getting this error.
All variables in input timetables must be numeric, datetime, or duration when synchronizing using 'mean'.
I understood what that meant so I deleted the coumns (variables) of the imported table that contain data that is not of these types. It worked once I did this, but I would like to know if there is a better way to do this so I don't have to go in and delete columns myself every time. I would like to import data columns (variables) that contain only these three types of data. Any help is appreciated! If you need, I can attach my table or text file that I am importing.
  3 Commenti
Forrest Ward
Forrest Ward il 24 Giu 2020
I'm attaching the text file. You can see from it that there are some variables that contains 'char' and non-numeric stuff. I am not trying to average non-numeric data which is why I would like to delete those columns or never import them in the first place.
dpb il 24 Giu 2020
Presuming these files all follow same format, I'd suggest building an importoptions object from the output of detectImportOptions that contains the selected input variables you want and use it when reading the files. You could possibly have more than one if there are different subsets of variables wanted for particular analyses.
This can be done once and saved in a .mat file and loaded and used for any file of the same structure.
Alternatively, you can just accept what readtable finds and then use isnumeric() on the columns to get rid of the unwanted columns after the fact.

Accedi per commentare.

Risposta accettata

Eric Sofen
Eric Sofen il 25 Giu 2020
You can use vartype to subscript into the table and select only variables that are a certain datatype (or meta-type like 'numeric'). Then, if you want the other data as well, you might circle back with ~vartype('numeric') and use one of the other retime aggregation methods (e.g. 'firstvalue') that will work with text data.

Più risposte (0)


Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by