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.
回答(2 个)
Dyuman Joshi
2023-11-3
temp_vars = temp_vars(~cellfun(@(x) any(ismissing(x)),temp_vars))
4 个评论
ML_Analyst
2023-11-3
Dyuman Joshi
2023-11-3
编辑:Dyuman Joshi
2023-11-7
@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
2023-11-3
How many does that remove? He wants to "to remove only the first empty".
Dyuman Joshi
2023-11-3
% make a cell array of string arrays with some missing elements:
str = ["some",missing,"string"];
C = repmat({str},1,3)
% remove the missing elements:
C = cellfun(@rmmissing,C,'UniformOutput',false)
类别
在 帮助中心 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!