hasfield1

This function look for a field in a structure and give back the structure tree branches until the field
6 download
Aggiornato 19 set 2019

Visualizza la licenza

create by Itamar Luzon 19.9.2019
this function look for a field in a structure and give back the structure tree
Branches until the field
inStruct is the name of the structure search
fieldName is the name of the field for which the function searches
input only inStruct and fieldName!!!
it is a recursive function, input of "ind" or "fieldtree" will make a mass
fieldtree is a cell matrix that contain by order the levels of
"fieldName" (return empty matrix if fieldName is not found)
level is the level of fieldName in inStruct structure

example
a.b.c=1;
a.b.d=2;
a.b.f.g=3;
a.h.rrr='lll';
a.t1.t2.t3.t4.t5=true;
a.t1.t2.t3.t4.t6='aaa';
disp('look for ''c''');
[fieldtree, level]=hasfield1 (a, 'c');
disp(fieldtree);
disp(level);
disp('look for ''t5''');
[fieldtree, level]=hasfield1 (a, 't5');
disp(fieldtree);
disp(level);
disp('look for ''t6''');
[fieldtree, level]=hasfield1 (a, 't6');
disp(fieldtree);
disp(level);
disp('look for ''g''');
[fieldtree, level]=hasfield1 (a, 'g');
disp(fieldtree);
disp(level);

results:
look for 'c'
'b' 'c'

2

look for 't5'
't1' 't2' 't3' 't4' 't5'

5

look for 't6'
't1' 't2' 't3' 't4' 't6'

5

look for 'g'
'b' 'f' 'g'

3

Cita come

itamar luzon (2025). hasfield1 (https://it.mathworks.com/matlabcentral/fileexchange/72806-hasfield1), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2019b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Data Type Identification in Help Center e MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.0.0