Ah, but the missing element is not a character vector, so this is not a cell array of character vectors
How to detect missing values in a string cell array
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Leon
el 8 de Mzo. de 2025
Comentada: Walter Roberson
el 9 de Mzo. de 2025
I have a cell array A like the below:
Columns 1 through 4
{'NAME'} {'STNNBR'} {[<missing>]} {'SAMPNO'} .
I tried to find the location of the missing value by doing the below:
B = ismissing(A)
Why is the value of B zero for all of them? Shouldn't the answer be: 0 0 1 0?
Columns 1 through 4
0 0 0 0
What is the correct way to write this code? Thanks.
2 comentarios
Stephen23
el 9 de Mzo. de 2025
"Why is the value of B zero for all of them? Shouldn't the answer be: 0 0 1 0?"
The ISMISSING documentation states that for a cell array of character vector ISMISSING returns TRUE for empty character vectors: "Missing values are defined according to the data type of A ... {''} — cell of character vectors"
Your data do NOT match this requirement.
"What is the correct way to write this code?"
Use a STRING array:
A = ["NAME", "STNNBR", missing, "SAMPNO"]
ismissing(A)
Respuesta aceptada
Walter Roberson
el 8 de Mzo. de 2025
You are applying ismissing() to a cell array. That is the same thing as calling
[ismissing(A(1)), ismissing(A(2)), ismissing(A(3)), ismissing(A(4))]
A(1), A(2), A(3), A(4) are all cells -- and the cells are not missing.
You should probably be using a string array rather than a cell array,
A = ["NAME", "STNNBR", nan, "SAMPNO"]
ismissing(A)
but if you insist on using a cell array then you should have something more like
B = {'NAME', 'STNNBR', string(nan), 'SAMPNO'};
cellfun(@(X)any(ismissing(X),'all'), B)
3 comentarios
Image Analyst
el 9 de Mzo. de 2025
Walter Roberson
el 9 de Mzo. de 2025
isempty: There is no data here.
ismissing(): There is data here, but some of it is marked as being invalid.
if isempty([]); disp('empty'); else; disp('not empty'); end
if ismissing([]); disp('missing'); else; disp('not missing'); end
C = {'ab', [1 2 missing], [], missing, ["cd", missing, "ef"]}
cellfun(@isempty, C, 'uniform', 0)
cellfun(@ismissing, C, 'uniform', 0)
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!