How to delete empty rows from string arrays contained in a cell array?

38 ビュー (過去 30 日間)
Davide Festa
Davide Festa 2020 年 7 月 10 日
コメント済み: Davide Festa 2020 年 7 月 10 日
I would need to delete empty strings contained in N x 1 string arrays (N is variable) which are contained in a cell array theirself.
mycellArray is a 3×1 cell array and is made up of string arrays of variable dimensions:
  • mycellArray{1} is a 49×1 string array
  • mycellArray{2} is a 22×1 string array
  • mycellArray{3} is a 35×1 string array
mycellArray{1} looks like:
How can I delete just the empty rows "" and let the written text?
Thanks in advance!

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 10 日
編集済み: madhan ravi 2020 年 7 月 10 日
Wanted = arrayfun(@(y)cellfun(@(x) x(~(x=="")), c{y},'un', 0),1:numel(c)).' % c your cell array
  3 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 10 日
編集済み: madhan ravi 2020 年 7 月 10 日
I answered your original question.
Davide Festa
Davide Festa 2020 年 7 月 10 日
fine, thank you anyway

サインインしてコメントする。

その他の回答 (1 件)

Arthur Roué
Arthur Roué 2020 年 7 月 10 日
% Logical array, true when element in cell is empty
vb = cellfun(@isempty, MyCell)
% Remove empty element
MyCell = MyCell(~vb)
  2 件のコメント
Davide Festa
Davide Festa 2020 年 7 月 10 日
Thanks for your answer, but my purpose is to delete empty strings contained in each string array of the cell.
Your suggest is to delete empty cells, but I have no empty cell, just empty strings ("") within string arrays which are part of a cell array.
Hope to be clear.
Arthur Roué
Arthur Roué 2020 年 7 月 10 日
編集済み: Arthur Roué 2020 年 7 月 10 日
Oh, ok I misunderstood the problem.
I think you have your answer below :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by