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!