필터 지우기
필터 지우기

How Can I determine minimum value in a double array?

조회 수: 29 (최근 30일)
Mira le
Mira le 2021년 11월 28일
댓글: Chunru 2021년 11월 29일
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

답변 (2개)

Image Analyst
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(:))
minValue = 2.2852
% Find all the rows and columns where that value occurs:
indexes = find(vect == minValue)
indexes = 1×2
2 4
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
Mira le
Mira le 2021년 11월 28일
an error display
Subscript indices must either be real positive integers or logicals.
in the line minValue = min(vect(:))
Image Analyst
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
Chunru 2021년 11월 28일
vect =[ 2.6660 2.2852 10.0000 3.2617 10.0000 10.0000 9.8532];
[vmin, idx] = min(vect)
vmin = 2.2852
idx = 2
  댓글 수: 4
Mira le
Mira le 2021년 11월 28일
I don't know where the problem is but the same error still display
I use matlab 2017a version
Chunru
Chunru 2021년 11월 29일
Then show your code so that we can help.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by