0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MATLAB cellの空欄チェック

0
Posted at
  1. 基本:列全体の空欄チェック(論理配列を返す)
    セル配列の特定の列に対して、どの要素が空([] や '')であるかを判定し、
    真偽値(1 または 0)のベクトルを取得

% サンプルデータの作成 (3行2列のセル配列)
% 1列目の2行目を []、3行目を '' (空欄) に設定
C = {'データ1', 100;
[], 200;
'', 300};

■1列目(すべての行)が空かどうかをチェック

columnIdx = 1; 
isEmptyMask = cellfun(@isempty, C(:, columnIdx));

disp(isEmptyMask);
% 出力:
%   0  (1行目はデータあり)
%   1  (2行目は [] なので空)
%   1  (3行目は '' なので空)

■空欄が「あるか・ないか」を一発で判定する

% 1列目に一つでも空欄があるか?
hasEmpty = any(cellfun(@isempty, C(:, 1))); % 結果: true (1)

% 1列目がすべて空欄か?
isAllEmpty = all(cellfun(@isempty, C(:, 1))); % 結果: false (0)

■ 空欄の行を特定して削除する・抽出する

% 1列目が空欄「ではない」行を抽出
validRows = C(~isEmptyMask, :);

disp(validRows);
% 出力: {'データ1', 100}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?