how to find the value of variable which is giving the minimum value of a function after iterations?

조회 수: 3 (최근 30일)
Ihere is an example of my question
A={[1 0 0; 0 1 0] [1 1 0;0 1 0]};
B={[2 1 2;2 2 1] [2 2 2; 2 1 1]};
for i=1:numel(A)
for j=1:numel(B)
c=A{i}.*B{j};
sumc=sum(c(:));
total{i,j}=sumc;
end
end
minValue=min([total{:}])
after getting the minimum value from iterations, how can I know which A,B values have generated this result?

답변 (1개)

Star Strider
Star Strider 2017년 1월 17일
The ind2sub function and the second output from min will probably do what you want:
[minValue,idx] = min([total{:}]);
[row_min, col_min] = ind2sub(size(total),idx)
row_min =
1
col_min =
2
The min function returns only the first instance of the minimum, so if there are more than one (there is only one here), you would need to use the find function to discover the row and column indices of all of them.
  댓글 수: 1
summyia qamar
summyia qamar 2017년 1월 17일
편집: summyia qamar 2017년 1월 17일
yes I got your point..Isn't there any way that we can get the whole matrix instead of its idx? because when we have large number of iterations like if A is cell of 64 matrices and b is 1806 then how can we find the values? for example in the given question. https://www.mathworks.com/matlabcentral/answers/320750-how-to-find-the-values-of-variables-which-give-minimum-value-of-a-function-after-iterations

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

카테고리

Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by