フィルターのクリア

understand if the cell is composed of all null elements

2 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 7 月 26 日
回答済み: Steven Lord 2023 年 7 月 26 日
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 ?

採用された回答

Steven Lord
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 = 1×5 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
C{3} = 1:10
C = 1×5 cell array
{0×0 double} {0×0 double} {[1 2 3 4 5 6 7 8 9 10]} {0×0 double} {0×0 double}
isempty(C) % false
ans = logical
0
size(C)
ans = 1×2
1 5
The cells inside the cell array in this case are empty. One way to determine this is to use cellfun.
identifyEmptyCells = cellfun(@isempty, C)
identifyEmptyCells = 1×5 logical array
1 1 0 1 1
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')
areAllTheCellsEmpty = logical
0
areAnyOfTheCellsEmpty = any(identifyEmptyCells, 'all')
areAnyOfTheCellsEmpty = logical
1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by