How do I check if all numbers in a vector are the same?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Samuele Bolotta
le 1 Avr 2021
Modifié(e) : Stephen23
le 1 Avr 2021
I have a row vector A. I'd like to verify whether all numbers in this vector are the same. How can I do this?
Thanks!
0 commentaires
Réponse acceptée
Stephen23
le 1 Avr 2021
Modifié(e) : Stephen23
le 1 Avr 2021
all(diff(A)==0)
min(A)==max(A) % does not work for NaN
range(A)==0 % RANGE requires the statistics toolbox
numel(unique(A))==1
1 commentaire
Robert Brown
le 1 Avr 2021
Stephen actually gave not only 1 but what appears to be 3 solutions to the problem ! very good ! (overachiever !)
I don't seem to have range(A). Is that in a newer version of MATLAB? or is it in a toolbox?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB 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!