Effacer les filtres
Effacer les filtres

Remove missing entries from nested cell array

5 vues (au cours des 30 derniers jours)
ML_Analyst
ML_Analyst le 3 Nov 2023
Hello,
I have a cell array which has string arrray inside like for example below:
and some of the string array have empty/missing contents:
I would like to remove these empty/missing entries from the overall cell_array (temp_vars).
I tried something like:
temp_vars = temp_vars(~cellfun('isempty',temp_vars))
but did not find a solution yet. Any help would be appreciated.

Réponses (2)

Dyuman Joshi
Dyuman Joshi le 3 Nov 2023
temp_vars = temp_vars(~cellfun(@(x) any(ismissing(x)),temp_vars))
  4 commentaires
Image Analyst
Image Analyst le 3 Nov 2023
How many does that remove? He wants to "to remove only the first empty".
Dyuman Joshi
Dyuman Joshi le 3 Nov 2023
Thanks for pointing out the mistake, @Image Analyst, I have updated my code.

Connectez-vous pour commenter.


Voss
Voss le 3 Nov 2023
% make a cell array of string arrays with some missing elements:
str = ["some",missing,"string"];
C = repmat({str},1,3)
C = 1×3 cell array
{["some" <missing> "string"]} {["some" <missing> "string"]} {["some" <missing> "string"]}
% remove the missing elements:
C = cellfun(@rmmissing,C,'UniformOutput',false)
C = 1×3 cell array
{["some" "string"]} {["some" "string"]} {["some" "string"]}

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by