How do I check if all numbers in a vector are the same?

1 view (last 30 days)
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!

Accepted Answer

Stephen23
Stephen23 on 1 Apr 2021
Edited: Stephen23 on 1 Apr 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 Comment
Robert Brown
Robert Brown on 1 Apr 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?

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by