Undefined function or variable 'isempty'.
Mostra commenti meno recenti
Hello all, I'm using version 2016a and have encountered some behaviour I've never seen before. I'm trying to check an excel spreadsheet to see if an entry already exists for a given serial number before adding a new entry. The problem section is:
recordsTable = readtable(FILE_ADDRESS, 'Sheet', systemSheet, 'Range', 'A:I'); % This reads in the data in a table
existingRecord = find(recordsTable.SerialNumbers == projectNum); % This finds any entries which match a given numerical value
if isempty(existingRecord) % This returns the error: Undefined function or variable 'isempty'.
...
end
I've used breakpoints to check and existingRecord is empty when isempty is called on it. Indeed, if I place a breakpoint on the problem line and then call isempty(existingRecord) from the command line instead of letting the script continue it works perfectly and returns a 1 as expected. Running each line individually from the command line also works and returns a 1 as expected. It is only when used as part of a script that MATLAB refuses to recognize isempty, despite it being a default function.
I have checked and isempty is on the MATLAB path as it should be. It is included as a built-in function in version 2016a, and my license is current. I've triple checked my spelling of all function and variable names and have spent several hours googling what could be wrong to no avail. No part of my code alters the path, and I'm not trying to use isempty or any variation thereof as a variable name. Any advice would be appreciated as at this point I have no idea why isempty seems to be unusable in a script, despite several hours of googling and reading documentation.
7 Commenti
Do you get something unexpected from the command
which -all isempty
Maybe a duplicate of the function made by you ?
Jan
il 17 Gen 2023
Please post a copy of the complete error message.
KG
il 17 Gen 2023
Walter Roberson
il 17 Gen 2023
Do you have a variable named isempty at any point? Possibly accidentally assign to it?
KG
il 17 Gen 2023
Walter Roberson
il 17 Gen 2023
When matlab saw {} in the code it deduced that isempty must be a variable, and so it does not search the path looking for it as a function.
Risposte (0)
Categorie
Scopri di più su Data Type Identification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!