How Can I determine minimum value in a double array?
    17 次查看(过去 30 天)
  
       显示 更早的评论
    
Hello every one;
 have an array :
vect =[ 2.6660    2.2852   10.0000    3.2617   10.0000   10.0000    9.8532]
I want to get the mininmum value as well as its position 
here in this vector:
min  = 2.2852
position = 2
please help me!
I need it to continue my program
Thank you
0 个评论
回答(2 个)
  Image Analyst
      
      
 2021-11-28
        Don't use the built-in min function.  It's second return argument will only return the location of the first occurrence of the min value.  A more robust and general solution is to use min() in combination with find():
vect =[ 2.6660    2.2852   10.0000    2.2852 3.2617   10.0000   10.0000    9.8532];
minValue = min(vect(:))
% Find all the rows and columns where that value occurs:
indexes = find(vect == minValue)
See how in this case, where the min occurred in two locations, it found both of them: one at vect(2) and another one at vect(4).
2 个评论
  Image Analyst
      
      
 2021-11-28
				clear('min'); % Get rid of your min variable you previously created.
vect =[ 2.6660    2.2852   10.0000    2.2852 3.2617   10.0000   10.0000    9.8532];
minValue = min(vect(:))
% Find all the rows and columns where that value occurs:
indexes = find(vect == minValue)
  Chunru
      
      
 2021-11-28
        vect =[ 2.6660    2.2852   10.0000    3.2617   10.0000   10.0000    9.8532];
[vmin, idx] = min(vect)
4 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


