struct 내부 field 값 여부 판단 (변수가 없을 때에 처리해줄 수 있는 방법이 없나요)
Info
This question is closed. Reopen it to edit or answer.
Show older comments
A 라는 1x1 struct 내부에 여러 필드를 만들었는데요 (A.name = 'John', A.age = '16'처럼)
학교 이름을 아는 경우에는 A.school='학교명' 처럼 입력해주고, 모르는 경우에는 따로 입력해주지 않았습니다.
A.school 변수가 존재하는 경우를 나누어서 처리할 함수가 있는데요.
모르는 경우를 찾아서 하나하나 A.school=NaN 처리를 해주는 방법 말고는 이 함수를 사용할 방법이 없을까요?
exist A.school, isempty(A.school) 을 쓰려고 하는데 A.school 값이 있을 때에는 해당 함수가 동작하지만,
A.school 값이 없을 때에는 '인식 할 수 없는 필드 이름 입니다' 라는 오류를 내서요.
대체할 수 있는 방법이 없을까 싶어 질문합니다.
2 Comments
This comment was flagged by MinJi KANG
isfield(A,'school')은 어떨까요?
https://kr.mathworks.com/help/matlab/ref/isfield.html
또는 그냥 try catch를 써도 좋을 것 같습니다.
MinJi KANG
on 21 Aug 2023
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!