Borrar filtros
Borrar filtros

minimun value in 2D array

28 visualizaciones (últimos 30 días)
Khawaja Asim
Khawaja Asim el 19 de Dic. de 2011
Respondida: Kevin Schroeder el 9 de Nov. de 2021
Can some body show me how to find minimum value in an image or 2D array along with its index. Regards

Respuestas (2)

Sean de Wolski
Sean de Wolski el 19 de Dic. de 2011
doc min;
And an example:
A = magic(100);
[Amin minidx] = min(A(:));

Kevin Schroeder
Kevin Schroeder el 9 de Nov. de 2021
I think you are looking for the minimum across both dimensions; something like this:
A = magic(5);
minValue = min(min(A));
[ind1, ind2] = find(A==minValue);
There are other ways to do this. For example, you can reshape the 2D array into a 1D array, and call min(), but then you have to convert the index back to the equivalent value for the 2D array using ind2sub(). I'm not sure wich is fast for large arrays, but the above method is more intuitive (in my opinion).

Categorías

Más información sobre Matrix Indexing 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