Hi all,
I have a complex set of structures, where I want to extract values from:
A: 1x1000 struct
sub-struct: B: 1x1 struct
sub-struct C: 1x3 struct
I want to search the A.B.C structures for var_a = x
var_a is part of C, but it does not exist in all C.
I tried "find", but I get "Reference to non-existent field 'C'."
Cheers

 採用された回答

Jan
Jan 2021 年 3 月 24 日

0 投票

"I want to search the A.B.C structures for var_a = x" - this is not clear yet.
"I tried "find", but I get "Reference to non-existent field 'C'."" - post the code and a copy of the complete error message. This allows for understanding the problem better than a vague paraphrasation of what you expect the code to do.
Try an approach like this:
Result = cell(1, 3000); % Maximum size
iR = 0;
for iA = 1:numel(A)
C = A(iA).C;
if isfield(C, 'var_a')
for iC = 1:numel(C)
iR = iR + 1;
Result{iR} = C(iC).var_a;
end
end
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Structures についてさらに検索

製品

リリース

R2016b

質問済み:

2021 年 3 月 22 日

回答済み:

Jan
2021 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by