Check if the value for a field in a struct exists

조회 수: 10 (최근 30일)
black cat
black cat 2025년 2월 10일
댓글: black cat 2025년 2월 10일
A struct can have a field name with no value. For example:
A=struct('a',{})
How can I check if this is the case?
I tried
isempty(A.a)
But an error says not enough input arguments.

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 10일
A=struct('a', {})
A = 0x0 empty struct array with fields: a
isempty(A)
ans = logical
1
isempty(A) || isempty(A.a)
ans = logical
1

추가 답변 (1개)

Matt J
Matt J 2025년 2월 10일
편집: Matt J 2025년 2월 10일
Watch your struct() syntax,
A=struct('a',[]) %field 'a' with empty matrix
A = struct with fields:
a: []
isempty(A.a)
ans = logical
1
B=struct('a',{{}}) %field 'a' with empty cell array
B = struct with fields:
a: {}
isempty(B.a)
ans = logical
1

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by