Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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 comentario
Walter Roberson
Walter Roberson el 19 de Abr. de 2016
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.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 19 de Abr. de 2016
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.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by