How to count between two range in Matlab?

조회 수: 1 (최근 30일)
Alex Rob
Alex Rob 2017년 2월 17일
댓글: Walter Roberson 2017년 2월 17일
Let's assume matrix A:
A = [25;30;34;20;26;20];
I want to create matrix B with the following criteria:
% First row: 20=< A < 25
% Second row 25=< A < 30
% third row 30=< A < 35
% forth row: 35=< A < 40
Output should be like:
B = [2;2;2;0]

답변 (1개)

Steven Lord
Steven Lord 2017년 2월 17일
Use histcounts.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 2월 17일
Arows = 58; Acols = 9;
A = randi([1 100], Arows, Acols);
B = histcounts(A, 1:100) .';
If that is not the solution, then the solution is
B = zeros(100,1);
because there are no integers that are "between" 1 and 2, or "between" 2 and 3.
Walter Roberson
Walter Roberson 2017년 2월 17일
A = [25;30;34;20;26;20];
B = histcounts(A, 20:5:40)

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

카테고리

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