Accessing all fields within a struct level at once
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vaishnavi
am 19 Dez. 2023
Bearbeitet: Nipun
am 21 Dez. 2023
If I have a struct A which looks like:
A.('one').('include') ; A.('two').('include'); A.('three').('dont include');
and so on, how can I directly check if 'dont include' is present in the third level of the structure without having to use a loop. Is this possible to achieve without implementing a loop?
2 Kommentare
Voss
am 19 Dez. 2023
'dont include' is not a valid field name, so what does the struct really look like?
Rather than describing the struct, maybe it's better to save it in a .mat-file and upload it here (using the paperclip button).
Akzeptierte Antwort
Weitere Antworten (1)
Nipun
am 21 Dez. 2023
Bearbeitet: Nipun
am 21 Dez. 2023
Hi Vaishnavi,
I understand that you are trying to find if "dontinclude" is a structure property without using for loops.
One possible solution is to create a function which evaluates every level of structure to check if the property is present.
Here is an example code with the listed recommendation
funcCheck = @(struct)isfield(struct,'dontinclude');
structfun(funcCheck,A)
Returns a "n x 1" logical array, where "n" is the number of levels in the structure.
Link to documentation:
Hope this helps.
Regards,
Nipun
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!