Concatenating tables with different format
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I am concatenating tables in a large loop. all these tables are imported from excel . sometimes Matlab imports the same column as in cells and sometimes as double which is leading to the following errors. For example:
Cannot concatenate the table variable 'TargetBook' because it is a cell in one table and a non-cell in another. the examples are numerous for different columns.
How can I force the concatenation by transforming one column type to fit the precedent table column type in order to concatenate successfully?
in other words
for k = 1:numel(List)
File = fullfile(Base,List(k).name);
Result = readtable(File);
if k==1
t20172018=Result;
else
t20172018=[t20172018;Result];
end
end
%% How can I make sure that Result concatenate to t20172018 no matter what the format of the column in Result is?
0 个评论
采纳的回答
Walter Roberson
2019-1-28
detectImportOptions on one of the files that gives you numeric results . Then readtable passing in the detected options each time.
It sounds as if some of the files have text notes in columns intended to be numeric . If so then processing those might be tricky .
2 个评论
Walter Roberson
2019-1-28
detect options first and use them for the first readtable . option detection is better at figuring out needed datatypes so readtable without it can give different types than with it, especially for r2018b with fields that look like times which option detection converts to duration but without detection is a cell array of character .
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!