Creating a table for a cell array with cell2table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Bogdan Cristea Eugen
am 26 Mai 2015
Bearbeitet: Stephen23
am 26 Mai 2015
Hi
Is there a limitation when creating a table from a cell array when the elements on a column don't have the same type ? This is the input cell array as shown in the command line:
tbl_content =
[ 9353] [ 493]
[ 7677] {1x1 cell}
[ 6931] [ 128]
and after conversion with cell2table
tbl = cell2table(tbl_content, 'VariableNames', col_names, ...
'RowNames', row_names);
I get
tbl =
ITALY BELGIUM
_____ _______
01-Jan-2010 00:00:00 9353 [493]
01-Feb-2010 00:00:00 7677 [NaN]
01-Mar-2010 00:00:00 6931 [128]
Why the first column doesn't have brackets for its elements, while the second column has ?
My intention is to put on the second cell of the second column in the cell array a NaN.
thanks Bogdan
0 Kommentare
Akzeptierte Antwort
Stephen23
am 26 Mai 2015
Bearbeitet: Stephen23
am 26 Mai 2015
I suspect that the data inside that {1x1 cell} is actually NaN, and that it is just being displayed slightly differently depending on which data container it is within.
What is the values of tbl_content{2,2} ?
In any case the cell2table documentation describes how it treats the columns as: "If the cell contents have different sizes or incompatible types, then the corresponding variable in the table, T, is a column of cells". If this is not the behavior you are getting, then this requires a bit more investigation.
Because NaN's are of class double (or single), then all you need to do is to ensure that all of the other numeric values are also of class double (or single), and then this concatenation should work correctly. There is no reason why you cannot use NaN as a placeholder for missing values.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!