Check if vector is increasing monotonely or just increasing
58 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have to check if the elements in a vector are in increasing order (or even equal to each other). In that case the function should return true. But if the following element is smaller, it should return false.
The function below doesn't pass tests if my vector is not monotonous, and I can't understand why?
function t = is_increasing(x)
k = 1
for k = 1:(length(x)-1)
if x(k+1) - x(k) > 0 || x(k+1) - x(k) == 0
t = true
k = k + 1
else
t = false
return
end
end
end
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Google 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!