How to count between two range in Matlab?
1 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
回答(1 个)
Steven Lord
2017-2-17
Use histcounts.
3 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!