x
is a struct
, right? In that case, according to this posting on the MATLAB newsgroup, there are two kinds of emptiness for structs:
S = struct()
=> no fieldsisempty(S)
is FALSE, becauseS
is a [1 x 1] struct without fieldsS = struct('Field1', {})
=> fields, but no dataisempty(S)
is TRUE, becauseS
is a [0 x 0] struct with fields
For me, isempty(fieldnames(S))
works only for the first case in Octave, at least.
If x
on the other hand, is an array, not a struct, then isempty(x)
should work.
>> S = struct()
S =
scalar structure containing the fields:
>> isempty(S)
ans = 0
>> isempty(fieldnames(S))
ans = 1
>> S = struct('Field1',{})
S =
0x0 struct array containing the fields:
Field1
>> isempty(S)
ans = 1
>> isempty(fieldnames(S))
ans = 0
>> x = []
x = [](0x0)
>> isempty(x)
ans = 1