understand if the cell is composed of all null elements
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi! How can I understand if the cell consists of all null elements? I tried this way but it doesn't seem to work:
CC = cell([3 7]);
empty_cell = ~isempty(CC); % result 1
or
load cc.mat
empty_cell = ~isempty(CC); % result 1 ?
댓글 수: 0
채택된 답변
Steven Lord
2023년 7월 26일
MATLAB is returning the correct result. The cell array is not empty, its size vector does not contain a 0.
C = cell(1, 5)
C{3} = 1:10
isempty(C) % false
size(C)
The cells inside the cell array in this case are empty. One way to determine this is to use cellfun.
identifyEmptyCells = cellfun(@isempty, C)
Depending on what question you want to ask, passing identifyEmptyCells into the any or all functions may be your next step.
areAllTheCellsEmpty = all(identifyEmptyCells, 'all')
areAnyOfTheCellsEmpty = any(identifyEmptyCells, 'all')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!