Avoid ''Dot indexing is not supported for variables of this type.'', exist(...) isn't working
1 view (last 30 days)
Show older comments
I want to check if the variable is valide.
I want to do this: stop(handle.UserData.sectionPowerSuply.tCyclic);
The Problem is that when there is an error while building the sectionPowerSuply this section dont exist.
is there a way to do something like this: exists(handle.UserData.sectionPowerSuply.tCyclic.Running)?
0 Comments
Answers (1)
Bjorn Gustavsson
on 26 Jun 2020
If you want to check if a struct has a field your're interested in you should check with isfield, check the help and documentation for that function. With your hierarcical struct it will be a couple of calls to be sure that the handle has a field 'UserData' first then the next field down, but you'll get there.
HTH
4 Comments
Walter Roberson
on 26 Jun 2020
No, when you give a structure reference, MATLAB will always say it does not exist as a variable. You need to test with isfield()
Bjorn Gustavsson
on 26 Jun 2020
Gabriel, that's good. However, when I test this in matlab-2020a:
qwe.asd = 1;
exist('qwe.zxc','var')
%
% ans =
%
% 0
% This is what you'd want
exist('qwe.asd','var')
%
% ans =
%
% 0
% This I'd guess you would want to be true?
So your solution might not be robust across matlab-versions, so maybe make a note to future you?
See Also
Categories
Find more on Variables 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!