which function to us to check if a struct name exists
Ältere Kommentare anzeigen
Dear all,
I am importing data in the form of a struct and the struct name is not the same everytime. Sometimes the struct is named a.b.c.d and sometimes it is named a.b.x.d. or a.b.c.x
I want to to perform a check if a.b.c.d exists before continueing the script.
1 Kommentar
Stephen23
am 5 Apr. 2022
Using the correct terminology would help you:
a.b.x.d
^ variable
^ field
^ field
^ field
There are multiple structures involved here (not one as you wrote), it helps to describe their relationship correctly.
Akzeptierte Antwort
Weitere Antworten (1)
Bruno Luong
am 5 Apr. 2022
try/catch after reading your struct
try
data = a.b.c.d;
catch
try
data = a.b.x.d;
try
data = a.b.c.x;
catch
error('I''m too tired to try something else')
end
end
end
1 Kommentar
Ruud Verschaeren
am 5 Apr. 2022
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!