How do I check if all numbers in a vector are the same?
4 次查看(过去 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!