How do i check for empty cells within a list

628 ビュー (過去 30 日間)
Andy 2011 年 9 月 21 日
コメント済み: WANG Jason 2020 年 4 月 29 日
How do i check for empty cells within list? I have a list of cells, namelist, and it has 12 values, i need to check if some of the cells are empty. Thanks


the cyclist
the cyclist 2011 年 9 月 21 日
It is not clear what you mean by a "list of cells". Can you provide some code that illustrates what types of variables you are using? For example, by "cells", do you mean cell arrays?
Without more details, it is hard to answer your question, but there are functions isempty() and cellfun() that might be useful to you.
Edited in response to your comments:
>> cellfun(@isempty,namelist)
does what I think you want. For example:
namelist = cell(2,6)
namelist{1} = 'abc'
namelist{12} = 3
  7 件のコメント
WANG Jason
WANG Jason 2020 年 4 月 29 日
This solution shows the power of Matrix:)


その他の回答 (1 件)

topdawgnate 2011 年 9 月 21 日
%Build Cell array (note the curly brackets)
A{1,1} = [1 4 3; 0 5 8; 7 2 9];
A{1,2} = 'Anne Smith';
A{2,1} = 3+7i;
A{2,2} = [];
Use the isempty function
isempty(A{2,2}) %Note the difference "{" and "(" brackets
This function will return 1.
Hope this helps. Nate
  2 件のコメント
the cyclist
the cyclist 2011 年 9 月 21 日
Be aware that this solution checks a single element within a cell array. My solution checks every element in the cell array individually, and reports whether each cell is empty or not. That might be more efficient, depending on your application.



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



Community Treasure Hunt

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

Start Hunting!

Translated by