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

조회 수: 7 (최근 30일)
Samuele Bolotta
Samuele Bolotta 2021년 4월 1일
편집: Stephen23 2021년 4월 1일
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!

채택된 답변

Stephen23
Stephen23 2021년 4월 1일
편집: Stephen23 2021년 4월 1일
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
Robert Brown
Robert Brown 2021년 4월 1일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by