how to find maximum value in d matrix of size (11*11)

1 visualización (últimos 30 días)
nishitha
nishitha el 5 de Oct. de 2014
Comentada: Image Analyst el 6 de Oct. de 2014
we have a matrix of size 11*11. can u please send me the matlab code to find maximum value in the matrix as soon as possible.

Respuesta aceptada

Yi
Yi el 5 de Oct. de 2014
Editada: Yi el 5 de Oct. de 2014
If the Matrix is X; then maximum value should be max(max(X)).
for d-dimension Matrix;
s=size(X);
MaximumValue=max(X);
for i=1:(length(s)-1)
MaximumValue=max(MaximumValue);
end;
  1 comentario
Image Analyst
Image Analyst el 5 de Oct. de 2014
No one familiar with MATLAB would have chosen this answer. First of all you wouldn't use a for loop when you can just use max() one time like I showed:
[maxValue, linIndexOfMax] = max(M(:))
Secondly s = [11,11] so length(s)-1 = 2-1 = 1, so the for loop just executes one time so there was no need for a loop even if you did have to call max again (which you don't). Even for a d-dimension array this loop is unnecessary - my code works for any dimension. I'd advice you not to use this answer's method. Though it works, most of the code is unnecessary and could have been done much more simply as
MaximumValue=max(X(:));
(which is what my code does) and get rid of all other lines of code.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Oct. de 2014
Not sure what "find" means - the value or the location - so I'll find both for you
[maxValue, linIndexOfMax] = max(M(:))
[row, column] = ind2sub(size(M), linIndexOfMax);
For example
M = magic(3)
[maxValue, linIndexOfMax] = max(M(:))
[row, column] = ind2sub(size(M), linIndexOfMax)
In the command window:
M =
8 1 6
3 5 7
4 9 2
maxValue =
9
linIndexOfMax =
6
row =
3
column =
2
  2 comentarios
Yi
Yi el 5 de Oct. de 2014
WOW, that's what I did not know. Thank you for the correction .
Image Analyst
Image Analyst el 6 de Oct. de 2014
Here's another quirk that trips people up all the time - it's about the size function as applied to images: http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by