How to find the index of missing values in a cell array without looping through each element?

39 ビュー (過去 30 日間)
S1 = struct();
S2 = struct();
C = {S1 S2 missing};

採用された回答

Voss
Voss 2022 年 7 月 11 日
You can use cellfun to call ismissing on the contents of each cell:
S1 = struct();
S2 = struct();
C = {S1 S2 missing}
C = 1×3 cell array
{1×1 struct} {1×1 struct} {1×1 missing}
is_missing = cellfun(@ismissing,C)
is_missing = 1×3 logical array
0 0 1
idx_missing = find(is_missing)
idx_missing = 3
(That's not got much loops.)

その他の回答 (1 件)

Bharat Chandra Mukkavalli
Bharat Chandra Mukkavalli 2022 年 7 月 11 日
Hi,
You can use the "cellfun()" function to apply a function to all the contents in a cell array. Further documentation on cellfun() can be found here: https://in.mathworks.com/help/matlab/ref/cellfun.html
Refer to link here on finding the indices of non-empty cells in a cell array: https://in.mathworks.com/matlabcentral/answers/42283-index-non-empty-cells-in-cell-array
Hope this helps!

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by