Borrar filtros
Borrar filtros

Count number of rows without NaNs

4 visualizaciones (últimos 30 días)
Pinga
Pinga el 3 de Oct. de 2014
Comentada: Pinga el 3 de Oct. de 2014
Hi!
I have a 10x2 cell. Each of these cells contains a 10x8 double. I'd like to count all the rows from column 2 (so Data{1,1}(:,2)) which don't have the vale "NaN" and have the value "1" in its row 8 (Data{1,1}(:,8).
What I've tried:
for n = 1:10
Result(:,n) = sum(~isnanData{1,1}(n,2),1(find(Data{1,1}(n,8) == 1)))
end
This seems not to work ("Error: Unbalanced or unexpected parenthesis or bracket.").
Thank you for any help!

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 3 de Oct. de 2014
sum(and(~isnan(Data{1,1}(:,2)),Data{1,1}(:,8)==1))
gives you the count of rows that don't have NaN on the second column and have 1 on 8th column
if you want to run that on all elements of your cell array you can do this:
func=@(D) sum(and(~isnan(D(:,2)),D(:,8)==1));
rowCount=cellfun(func,Data);
  1 comentario
Pinga
Pinga el 3 de Oct. de 2014
Great, this works great! Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 3 de Oct. de 2014
You can't have ,1(find. Why is there a ( right after the 1?????

Categorías

Más información sobre Creating and Concatenating Matrices 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!

Translated by