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

13 ビュー (過去 30 日間)
Forrest Ward
Forrest Ward 2020 年 6 月 24 日
回答済み: Eric Sofen 2020 年 6 月 25 日
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 件のコメント
Forrest Ward
Forrest Ward 2020 年 6 月 24 日
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
dpb 2020 年 6 月 24 日
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.

サインインしてコメントする。

採用された回答

Eric Sofen
Eric Sofen 2020 年 6 月 25 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by