How can I which value that be used to calculate a function

조회 수: 1 (최근 30일)
Tianze Li
Tianze Li 2019년 5월 14일
댓글: Fangjun Jiang 2019년 5월 17일
In this casue, I difine a range for x and y, and then calculated the min value of L, but how do i find which x vaule and y value to calculate the min L? Many thanks!!!!!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2019년 5월 14일
편집: Fangjun Jiang 2019년 5월 14일
You need to run min() twice
A=magic(5);
[MinInCol,RowIndex]=min(A);
[MinValue,ColIndex]=min(MinInCol);
Position=[RowIndex(ColIndex),ColIndex];
or better
[MinValue,Index]=min(A(:));
[Ix,Iy]=ind2sub(size(A),Index)
  댓글 수: 2
Tianze Li
Tianze Li 2019년 5월 17일
Yes. It did show the row and coloum for both x and y. But how can i display the value from that row and coloum instead of to find them from the array
Fangjun Jiang
Fangjun Jiang 2019년 5월 17일
Not clear what you mean. Maybe in your example, you are looking for x(Ix), y(Iy)?

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

추가 답변 (1개)

Steven Lord
Steven Lord 2019년 5월 14일
Since you indicate that you're using release R2019a, call min with the 'linear' option and two output arguments. This will give you the linear index of the minimum value, and you can use that index into x and y.

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by