- creates a cell array of tables and empty cells
- determines which cells contain a table
- counts the number of tables per row
Find the number of non-empty cells in each row of a cell array
조회 수: 32 (최근 30일)
이전 댓글 표시
I have a cell array of tables where each row contains data for one specimen and each column of that row contains results of repeated tests for that specimen. There are different numbers of tests in each row.
I would like to process each row based on the number of tests. How can I determine the number of cells in each row that contain tables? For example, the first row contains 12 cells, the second contains 14, etc.
댓글 수: 0
채택된 답변
Adam Danz
2022년 11월 17일
편집: Adam Danz
2022년 11월 17일
Here's a demo that
c = cell(3,4);
c([1,2,3,4,6,10,12]) = {array2table(rand(5))}
y = cellfun(@istable, c)
nTablesPerRow = sum(y,2)
If you'd rather count any cell that is not empty,
y2 = ~cellfun(@isempty, c)
nNonEmptiesPerRow = sum(y2,2)
댓글 수: 12
Adam Danz
2022년 11월 30일
Ah, of course. Thanks @Jim McIntyre. That's what I get for running code in my head rather than actually testing it 😊
I'll update my previous comment to avoid confusions for any future visitors.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!