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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Blackadder
le 8 Oct 2016
Modifié(e) : Blackadder
le 9 Oct 2016
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 commentaires
Plus de réponses (1)
Andrei Bobrov
le 9 Oct 2016
Modifié(e) : Andrei Bobrov
le 9 Oct 2016
sum(x(:) > k(:)') % in r2016b
2 commentaires
Blackadder
le 9 Oct 2016
Interesting! This does not work in r2014a ("Matrix dimensions must agree" error).
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!