Remove missing entries from nested cell array

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.

Respuestas (2)

Dyuman Joshi
Dyuman Joshi el 3 de Nov. de 2023
temp_vars = temp_vars(~cellfun(@(x) any(ismissing(x)),temp_vars))

4 comentarios

ML_Analyst
ML_Analyst el 3 de Nov. de 2023
Hello @Dyuman Joshi I dont want to remove the entire cell, for example your code removes the temp_vars{1,6} cell completely.
But i want to remove only the first empty empty/missing string in the cell. Basically temp_vars{1,6}(1,2) which is "t_mass_graphic" should be shifted to temp_vars{1,6}(1,1)
Dyuman Joshi
Dyuman Joshi el 3 de Nov. de 2023
Editada: Dyuman Joshi el 7 de Nov. de 2023
@ML_Analyst, As you mentioned overall cell_array, I interpreted it like that.
Nevertheless, in that case -
for k = 1:numel(temp_vars)
idx = find(ismissing(temp_vars{k}), 1);
temp_vars{k}(idx) = [];
end
Image Analyst
Image Analyst el 3 de Nov. de 2023
How many does that remove? He wants to "to remove only the first empty".
Dyuman Joshi
Dyuman Joshi el 3 de Nov. de 2023
Thanks for pointing out the mistake, @Image Analyst, I have updated my code.

Iniciar sesión para comentar.

% 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"]}

Productos

Versión

R2021b

Preguntada:

el 3 de Nov. de 2023

Editada:

el 7 de Nov. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by