i have a vector x=[1 2 3 1 4 4.3 3 3.7 4.8],consider a variable k=4:0.2:5, how many values of x are greater than k(i.e) so the output will show [2 1 1 0 0]
1 次查看(过去 30 天)
显示 更早的评论
i have a vector x=[1 2 3 1 4 4.3 3 3.7 4.8], consider a variable k=4:0.2:5, I need to find how many values of x are greater than k(i.e)
so the output will show [2 1 1 0 0]
0 个评论
采纳的回答
Blackadder
2016-10-8
编辑:Blackadder
2016-10-9
First, with x and k as defined by you, the output should be
[2 2 1 1 0 0]
You can compute this by
x = [1 2 3 1 4 4.3 3 3.7 4.8];
k = 4:0.2:5;
sum(bsxfun(@gt,x',k))
0 个评论
更多回答(1 个)
Andrei Bobrov
2016-10-9
编辑:Andrei Bobrov
2016-10-9
sum(x(:) > k(:)') % in r2016b
2 个评论
Blackadder
2016-10-9
Interesting! This does not work in r2014a ("Matrix dimensions must agree" error).
另请参阅
类别
在 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!