필터 지우기
필터 지우기

The min(y) function where y is a vector

조회 수: 1 (최근 30일)
Euan
Euan 2011년 11월 12일
If i have used a loop say
for x=1:1:10
y(x)=(x^2)/2
end
then use min(y) to display the minimum from this vector, 0.5. How would I get it to display the corresponding x value?
thanks

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 12일
In your code, x is a scalar. It is over-written every iteration in the for-loop.
min() can return the index.
x=1:10;
y=x.^2/2;
[ymin,pos]=min(y);
x_val=x(pos)

Wayne King
Wayne King 2011년 11월 12일
[minval,index] = min(y);
In this case it's trivial since index is the x value at which the minimum occurs. This function is increasing on your x values, so the minimum is at the first element.

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by