필터 지우기
필터 지우기

How to find min value among 20 random matrices and return the min matrix have the min value ?

조회 수: 2 (최근 30일)
if i have a matrix A like this
A = [1 0 1 1
0 0 1 0
0 1 0 1
1 1 0 1]
and create a 20 random (4,4) matrix and do some replacement in s
popSize = 20;
for k=1:popSize
s = randi ([0 1 ] ,n,m);
s(1,:) = A (1,:);
s (4,:) = A (4,:);
s(:,4) = A (:,4);
S11(k)=(sum (sum(A ~= s)));
end
min = S11(k)
S10= S11(min);
how can i correct this code and after find the min value return the matrix that have the min value
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 4월 19일
You know, I have given up on responding to you because you keep duplicating your questions. You already have an active Question on exactly this topic, http://www.mathworks.com/matlabcentral/answers/279483-if-i-have-random-matrices-how-to-find-a-specific-matrix and you let it sit for 22 hours without responding to it, but suddenly you responded there and then opened a duplicate question because you wanted a faster response.
The most active volunteers here have a dual role: they answer questions, but they also try to clean up, removing duplicate conversations and redirecting duplicate conversations to all happen in one thread. Every time you create a duplicate question, you reduce the time we have available to actually answer questions, because we have to instead spend the time being janitors.
Now Azzi is going to be left hanging about reasons why his suggested code did not work for you, and it is going to turn out to be because you did not use his code, you used code in which you tried to use "min" as a variable and a function as well. If the conversation had been left in that other Question then that would have been immediately obvious.

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

답변 (1개)

Image Analyst
Image Analyst 2016년 4월 19일
Do not use min as a variable name because it's a built in function.
Do this:
% Find min in S11
[minValue, indexOfMin] = min(S11)
% Extract all the min values into S10.
S10 = S11(S11 == minValue);
% S10 will have varying numbers of elements
% but all elements will have the value minValue.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by