필터 지우기
필터 지우기

Count number of rows without NaNs

조회 수: 3 (최근 30일)
Pinga
Pinga 2014년 10월 3일
댓글: Pinga 2014년 10월 3일
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!

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 10월 3일
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
Pinga
Pinga 2014년 10월 3일
Great, this works great! Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 10월 3일
You can't have ,1(find. Why is there a ( right after the 1?????

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by