필터 지우기
필터 지우기

Creating a table for a cell array with cell2table

조회 수: 1 (최근 30일)
Bogdan Cristea Eugen
Bogdan Cristea Eugen 2015년 5월 26일
편집: Stephen23 2015년 5월 26일
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

채택된 답변

Stephen23
Stephen23 2015년 5월 26일
편집: Stephen23 2015년 5월 26일
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개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by