sum logical 1's independently for each column
조회 수: 5 (최근 30일)
이전 댓글 표시
I've attached a sample data from excel.
how can I create a "for loop" to sum each column and give me print out total for each column.
I also need to compare the "length" of the column to the sum of the logical 1's in that column then print out a pass or fail for each column tested.
example:
1 1 1 1
1 1 1 1
1 1 1 0
1 1 1 1
-----------sum
first column = 4 ==length(column) = pass
fourth column = 3 == lenght(column = fail
댓글 수: 0
채택된 답변
추가 답변 (2개)
David Hill
2022년 2월 12일
No loop is needed.
r=readmatrix('logicalDataCount.xlsx');
s=sum(r);
l=s==size(r,1);
댓글 수: 10
David Hill
2022년 2월 13일
The below code is completely flexible (does not depend on the size of r)
s=sum(r);
allPassed = (numPasses == size(r, 1));
You are really not understanding, the logical array above tells you every column that is passed (1) or failed (0). Converting the logical array to 'pass' or 'fail' is trivial.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!