how to find maximum and minimum in a matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maryam Hamrahi
el 4 de Ag. de 2016
Comentada: Maryam Hamrahi
el 4 de Ag. de 2016
I have matrix A with n rows and 2 columns. I would like to find rows which has the maximum and/or minimum of X and/or Y. Then, replace zero in these rows.
For instance: I have matrix A and I would like to produce matrix B.
A= [0.1 0.5
0.3 0.9
0.4 0.8
0.4 0.2
1 0.7
0.2 0.6
0.7 1
0.2 0.9]
Here, max. X=1 min. X=0.1 max. Y=1 min. Y=0.2
B= [0 0
0.3 0.9
0.4 0.8
0 0
0 0
0.2 0.6
0 0
0.2 0.9]
0 comentarios
Respuesta aceptada
Thorsten
el 4 de Ag. de 2016
A= [0.1 0.5
0.3 0.9
0.4 0.8
0.4 0.2
1 0.7
0.2 0.6
0.7 1
0.2 0.9]
idx = A(:,1)==max(A(:,1)) | A(:,1)==min(A(:,1)) |...
A(:,2)==max(A(:,2)) | A(:,2)==min(A(:,2));
A(any(idx,2),:) = 0
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!