which function to us to check if a struct name exists
Show older comments
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 Comment
Stephen23
on 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.
Accepted Answer
More Answers (1)
Bruno Luong
on 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 Comment
Ruud Verschaeren
on 5 Apr 2022
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!