isempty: Not enough input arguments.
Ältere Kommentare anzeigen
Dear All,
I have an empty structure x.y.z
isfield(x.y, 'z') is logical 1, but
isempty(x.y.z) gives me this error:
Error using isempty
Not enough input arguments.
How to check that z is empty? Thank you,
OL
1 Kommentar
Adam Danz
am 19 Mär. 2020
You shouldn't get that error.
x.y.z = [];
isfield(x.y,'z') % = true
isempty(x.y.z) % = true
Confirm that you're using Matlab's isempty function.
which isempty -all
The output should include a list of built-in functions/methods.
Akzeptierte Antwort
Weitere Antworten (2)
Fangjun Jiang
am 19 Mär. 2020
Do you have an example data?
>> x.y.z=[]
x =
struct with fields:
y: [1×1 struct]
>> isempty(x.y.z)
ans =
logical
1
Image Analyst
am 19 Mär. 2020
It should work. See this:
% Assign x.y.z to some value.
x.y.z = 10
tf = isempty(x.y.z) % Shows false
% Now make field z empty.
x.y.z = []; % Null, empty
tf = isempty(x.y.z) % Shows true
% Remove the field z
x.y = rmfield(x.y, 'z')
tf = isempty(x.y.z) % Throws error
Attach your data if you still have trouble.
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!