필터 지우기
필터 지우기

Remove missing entries from nested cell array

조회 수: 5 (최근 30일)
ML_Analyst
ML_Analyst 2023년 11월 3일
편집: Dyuman Joshi 2023년 11월 7일
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
Dyuman Joshi 2023년 11월 3일
temp_vars = temp_vars(~cellfun(@(x) any(ismissing(x)),temp_vars))
  댓글 수: 4
Image Analyst
Image Analyst 2023년 11월 3일
How many does that remove? He wants to "to remove only the first empty".
Dyuman Joshi
Dyuman Joshi 2023년 11월 3일
Thanks for pointing out the mistake, @Image Analyst, I have updated my code.

댓글을 달려면 로그인하십시오.


Voss
Voss 2023년 11월 3일
% 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"]}

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by