are the first 3 elements of a vector NaN?

1 visualización (últimos 30 días)
Sabbas
Sabbas el 11 de Ag. de 2012
Dear all,I have
A={
[NaN]
[NaN]
[NaN]
[3]
[3]
[6]
[4]}
I want to find a rule that will tell me if the first 3 elements of a vector A are NaN or not
thanks
  2 comentarios
Yash
Yash el 11 de Ag. de 2012
you can apply condition on them
Sabbas
Sabbas el 11 de Ag. de 2012
coul;d you please be more specific?

Iniciar sesión para comentar.

Respuesta aceptada

Matt Fig
Matt Fig el 11 de Ag. de 2012
A is a cell.
all(cellfun(@isnan,A(1:3)))

Más respuestas (1)

Image Analyst
Image Analyst el 11 de Ag. de 2012
Editada: Image Analyst el 11 de Ag. de 2012
Method 1. Inspects the first three cells ONLY.
A = {
[NaN]
[NaN]
[NaN]
[3]
[3]
[6]
[4]}
if isnan(A{1}) && isnan(A{2}) && isnan(A{3})
uiwait(msgbox('The first three cells are nans'));
else
uiwait(msgbox('The are not nans.'));
end
Method 2. Somewhat more robust and flexible.
% Define starting and ending cell to inspect.
firstElementToCheck = 1;
lastElementToCheck = 3;
nanLocations = isnan([A{:}])
if sum(nanLocations(firstElementToCheck:lastElementToCheck)) == (lastElementToCheck - firstElementToCheck) + 1
message = sprintf('The cells between %d and %d are all NaNs', ...
firstElementToCheck, lastElementToCheck);
uiwait(msgbox(message));
else
message = sprintf('The cells between %d and %d are NOT ALL NaNs', ...
firstElementToCheck, lastElementToCheck);
uiwait(msgbox(message));
end

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by