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

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!

 Réponse acceptée

madhan ravi
madhan ravi le 10 Juil 2020
Modifié(e) : madhan ravi le 10 Juil 2020
Wanted = arrayfun(@(y)cellfun(@(x) x(~(x=="")), c{y},'un', 0),1:numel(c)).' % c your cell array

3 commentaires

First of all thanks for the answer. I think the direction is good.
However, what I get if I type Wanted{1} is
Wanted{1}
ans =
49×1 cell array
{0×0 char}
{0×0 char}
{0×0 char}
{'S' }
{0×0 char}
{0×0 char}
{'9' }
{0×0 char}
{'9' }
{0×0 char}
{0×0 char}
{'9' }
I would like Wanted to be again a cell array of string arrays(just like % c your cell array).
For example, what I look for is Wanted{1} to be a 49x1 string array with NOT only the first character of every row (as you can see on the 4th row I just got 'S'), but I need the whole line of text. And of course I don't need the empty lines.
Thanks
madhan ravi
madhan ravi le 10 Juil 2020
Modifié(e) : madhan ravi le 10 Juil 2020
I answered your original question.
fine, thank you anyway

Connectez-vous pour commenter.

Plus de réponses (1)

% Logical array, true when element in cell is empty
vb = cellfun(@isempty, MyCell)
% Remove empty element
MyCell = MyCell(~vb)

2 commentaires

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é le 10 Juil 2020
Modifié(e) : Arthur Roué le 10 Juil 2020
Oh, ok I misunderstood the problem.
I think you have your answer below :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by