Count the number of times a value appears in a row and save the row number
조회 수: 3 (최근 30일)
이전 댓글 표시
I wanted to sort points in an array based on how many times a number less than or equal to 1.5 appears in the row. I want to save the row index number of those that have 3 or more occurences less than or equal to the target value of 1.5. I have placed the array below. If you have any ideas on how to do this that would be great. Thanks for your time.
A = [NaN 1.00000000000000 1.00000000000000 1.99994495218295 1.40991828545270 1.98465118243128 2.97995391814023 1.41286932041226 1.44150019470391 2.30703739193881
1.00000000000000 NaN 1.41618367600370 0.999999999999996 1.00000000000000 2.11349467948903 1.98589244648483 1.00000000000000 1.73544845449717 1.98611502337309
1.00000000000000 1.41618367600370 NaN 2.24512987514306 2.20570040562793 0.999999999999996 3.22884118121504 1.75480404405606 1 3.15259384660772
1.99994495218295 0.999999999999996 2.24512987514306 NaN 1.40867173007472 2.65578172203034 1.00000000000000 1.41514975278174 2.44463958996392 2.12446752335984
1.40991828545270 1.00000000000000 2.20570040562793 1.40867173007472 NaN 3.01897607767301 2.11695260794737 1.62219494319153 2.57847672580517 1.00000000000000
1.98465118243128 2.11349467948903 0.999999999999996 2.65578172203034 3.01897607767301 NaN 3.52998354037453 2.38833466800397 1.41223022448087 3.96751962825988
2.97995391814023 1.98589244648483 3.22884118121504 1.00000000000000 2.11695260794737 3.52998354037453 NaN 2.21498386821498 3.35954605769311 2.49207458085697
1.41286932041226 1.00000000000000 1.75480404405606 1.41514975278174 1.62219494319153 2.38833466800397 2.21498386821498 NaN 1.44673037867744 2.53341581840774
1.44150019470391 1.73544845449717 1 2.44463958996392 2.57847672580517 1.41223022448087 3.35954605769311 1.44673037867744 NaN 3.56150161869124
2.30703739193881 1.98611502337309 3.15259384660772 2.12446752335984 1.00000000000000 3.96751962825988 2.49207458085697 2.53341581840774 3.56150161869124 NaN];
댓글 수: 0
채택된 답변
Star Strider
2020년 10월 6일
Try this:
rowsum = sum((A <= 1.5), 2);
result = find(rowsum >= 3)
producing:
result =
1
2
3
4
5
8
9
Those could be combined into one line:
result = find(sum((A <= 1.5), 2) >= 3)
I kept them separate for clarity.
댓글 수: 4
Star Strider
2020년 10월 6일
That’s what I thought, although I wanted to explain the other options.
As always, my pleasure!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!