- "If the contents of the cells in a column of C have compatible sizes and types, then the corresponding table variable is the vertical concatenation of those contents into an array."
- "If the contents of the cells in a column have different sizes and types, then the corresponding table variable is a cell array."
Inconsistent type following cell2table
조회 수: 8 (최근 30일)
이전 댓글 표시
Converting cell array with cell2table results in inconsistent conversion of arrays depending on (as far as I can tell) other members of the table column. Unfortunately this is causing issues for me, is there any simple fix that does not require changing inputs on a case-by-case basis?
MRE:
test = {[1, 2], [nan]; [nan], [nan]; [nan], [nan]};
test_table = cell2table(test);
test_table{2, 1}{1}; % okay (returns nan)
test_table{2, 2}{1}; % error: Brace indexing is not supported for variables of this type.
댓글 수: 2
Stephen23
2022년 5월 3일
"Converting cell array with cell2table results in inconsistent conversion of arrays depending on (as far as I can tell) other members of the table column."
Your 1st column will be a cell array (because [1,2] cannot be concatenated vertically with NaN), and because scalar NaNs can be concatenated the 2nd column will be numeric. Lets now check with your example data:
C = {[1,2],nan;nan,nan;nan,nan}
T = cell2table(C)
So far eveything seems to be working exactly as documented and as expected.
What do you expect the 1st column to be?
What do you expect the 2nd column to be?
채택된 답변
Star Strider
2022년 5월 3일
Use parentheses, not curly braces, to index into a vector within a cell —
test = {[1, 2], [nan]; [nan], [nan]; [nan], [nan]};
test_table = cell2table(test)
test_table{2, 1}(1) % okay (returns nan)
test_table{2, 2}(1) % error: Brace indexing is not supported for variables of this type.
test_table{1,1}
test_table{1,1}{1}(1)
test_table{1,1}{1}(2)
The indexing can get a bit complicated.
.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!