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

 Réponse acceptée

Jan
Jan le 24 Mar 2021

0 votes

"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

Plus de réponses (0)

Catégories

Produits

Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by