How do I check if all numbers in a vector are the same?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!