Avoid ''Dot indexing is not supported for variables of this type.'', exist(...) isn't working
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Bjorn Gustavsson
2020년 6월 26일
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
Walter Roberson
2020년 6월 26일
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
2020년 6월 26일
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!